Alternatively, you may write the two low-order 16-bit words in a "traditional" way to represent IPv4 addresses:

Code

0:0:0:0:0:0:13.1.68.3 0:0:0:0:0:FFFF:129.144.52.38

As all of these are obviously very long, [url=http://rfc.net/rfc1884.html]RFC 1884 suggests a zero-compressed representation, where one series of consecutive zero groups can be replaced by a double colon. And, of course, leading zeros are always redundant.

With the fewest number of characters possible, write a Perl program that reads a series of valid, newline separated, arbitrary IPv6 addresses from standard input and writes a series of newline separated compressed representations of these addresses to standard output. The output must hold the shortest possible compression of the IPv6 address in case more than one solution is possible.

The Rules

Your script must run under the latest stable Perl distribution (currently 5.6.1). You may exploit all bugs in that distribution if that helps to improve your score. You may use all standard modules that came with the distribution. Your script may not be platform-dependent and it may not use other programs or scripts.

The Score

The score is the sum of all characters. However, you may use a line similar to the following one right at the start of your script:

Code

#!/usr/bin/perl

Everything between "#!" and "perl" (including both) does not count, as well as the newline character you put at the end of that line. Each character you put in between "perl" and the end of the line will count. For example, the following script has a score of 8 (3 for the " -n" and 5 for the "print").

Code

#!/usr/local/bin/perl -nprint

The End

A score of less than 100 is possible. You should consider to put your solution in a spoiler tag (see [url=http://perlguru.com/gforum.cgi?do=markup_help;]Get Markup Help), so others who want to play don't see your solution right away.

Have a lot of fun!

-- mhx At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."

Yes, when written in "true" IPv6 style. When written in "IPv4 compatibility" style, the last part of the address is written like an IPv4 address (like in the examples I gave). But in general, IPv6 addresses are always written in hex.

In Reply To

and what will 1::2::3 expand to?

Nothing will expand. This golf course is about compressing. The address you gave is not a valid IPv6 address, since only one series of zero groups may be replaced by a double colon. If there are more than one, like in

Code

1:0:0:0:1:0:0:1

you could compress that to one of

Code

1::1:0:0:1 1:0:0:0:1::1

For the game, I always want the shortest possible compression, i.e. the one the removes most of the zeroes.

-- mhx At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."