Created
October 5, 2009 20:48
-
-
Save kriskowal/202458 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
golf () { | |
echo ip: $1; | |
echo -n "A: " | |
perl -e '$p=qr!(?:0|1\d{0,2}|2(?:[0-4]\d?|5[0-5]?|[6-9])?|[3-9]\d?)!;print((shift=~m/^$p\.$p\.$p\.$p$/)?1:0);' $1; echo | |
echo -n "B: " | |
perl -e '$p=qr!(?:0|1\d{0,2}|2(?:[0-4]\d?|5[0-5]?|[6-9])?|[3-9]\d?)!;exit shift !~ m/^$p\.$p\.$p\.$p$/;' $1 && echo pass || echo fail | |
echo -n "C: " | |
perl -e '$p=qr{(?:0|1\d{0,2}|2(?:[0-4]\d?|5[0-5]?|[6-9])?|[3-9]\d?)};exit shift !~ m/^$p\.$p\.$p\.$p$/;' $1 && echo pass || echo fail | |
echo -n "D: " | |
perl -e '$p=qr{(\d+)}; exit not (shift =~ m/^$p\.$p\.$p\.$p$/ and not grep {$_ < 0 or $_ >= 256} $1, $2, $3, $4);' $1 && echo pass || e | |
echo -n "E: " | |
perl -e '@_ = split /\./, shift; exit -1 if @_ != 4 or grep {!/^\d+$/ or $_ < 0 or $_ >= 256} @_' $1 && echo pass || echo fail | |
echo -n "F: " | |
perl -e '@_=split/\./,shift;exit -1 if @_!=4 or grep{!/^\d+$/ or $_< 0 or $_>=256}@_' $1 && echo pass || echo fail | |
} | |
golf "1.2.3.4" | |
golf "1.2.3" | |
golf "1.2.3.4.5" | |
golf "1.2.3.256" | |
golf "1.2.3.a" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment