Skip to content

Instantly share code, notes, and snippets.

@turugina
Created August 4, 2012 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turugina/3257143 to your computer and use it in GitHub Desktop.
Save turugina/3257143 to your computer and use it in GitHub Desktop.
lldecade きみならどう書く online の回答
use strict;use warnings;use utf8;my($xx,$x,$X,@x,@X)=qr!\p{xdigit}!;
sub X{0 eq$_||!/^0+[^0]+$/}@x=(sub{/^$xx{2}([-:])(?:$xx{2}\1){4}$xx{2}$/},
sub{@X=split/\./;4==@X&&4==grep{/^\d{1,3}$/&&0<=$_&&256>$_&&X}@X},
sub{@X=split/:/;8==@X&&8==grep{/^$xx{1,4}$/&&X}@X});
sub x{$X=0;for$x(@x){last if$x->();++$X;}$X;}@x=map x,<STDIN>;
@x=map{$_*=4;$x[$_]*64+$x[$_+1]*16+$x[$_+2]*4+$x[$_+3]}0..$#x/4;
print join'',map chr,@x;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment