
mhx
Enthusiast
/ Moderator
Feb 16, 2002, 6:58 AM
Post #1 of 9
(65312 views)
|
[GOLF] IPv6 Address Compression
|
Can't Post
|
|
Let's play another little one-hole course here... 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:
FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 1080:0000:0000:0000:0008:0800:200C:417A FF01:0:0:0:0:0:0:43 0:0:0:0:0:0:0:0 Alternatively, you may write the two low-order 16-bit words in a "traditional" way to represent IPv4 addresses:
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. So, these IPv6 addresses...
1080:0000:0000:0000:0008:0800:200C:417A FF01:0:0:0:0:0:0:43 0:0:0:0:0:0:0:1 0:0:0:0:0:0:0:0 0:0:0:0:0:0:013.001.068.003 0:0:0:0:0:FFFF:129.144.52.38 ...can be turned into these compressed IPv6 addresses...
1080::8:800:200C:417A FF01::43 ::1 :: ::13.1.68.3 ::FFFF:129.144.52.38 ...with a Perl script, of course The Task 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: 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").
#!/usr/local/bin/perl -n print
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."-- Frodo
|