Feb 16, 2002, 6:58 AM
Post #1 of 9
Let's play another little one-hole course here...
[GOLF] IPv6 Address Compression
The Problem: Zero-Compression of IPv6 Addresses
Anyone who's aware of IPv6 addresses knows they can be quite long. They are normally represented as 8 hexadecimal 16-bit words, separated by colons:
Alternatively, you may write the two low-order 16-bit words in a "traditional" way to represent IPv4 addresses:
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.
So, these IPv6 addresses...
...can be turned into these compressed IPv6 addresses...
...with a Perl script, of course
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.
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 is the sum of all characters. However, you may use a line similar to the following one right at the start of your script:
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").
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!
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."