diff options
| -rw-r--r-- | challenge-166/james-smith/perl/ch-1.pl | 15 | ||||
| -rw-r--r-- | challenge-166/james-smith/perl/ch-2.pl | 22 |
2 files changed, 27 insertions, 10 deletions
diff --git a/challenge-166/james-smith/perl/ch-1.pl b/challenge-166/james-smith/perl/ch-1.pl index 4661645196..6afd01060d 100644 --- a/challenge-166/james-smith/perl/ch-1.pl +++ b/challenge-166/james-smith/perl/ch-1.pl @@ -8,15 +8,24 @@ use Test::More; use Benchmark qw(cmpthese timethis); use Data::Dumper qw(Dumper); $Data::Dumper::Sortkeys = 1; -my $re = 'abcdefoilst'; + my $words = []; + +my $ACTION = 'any'; +# $ACTION = 'numbers'; +# $ACTION = '2numbers'; + $ACTION = 'letters'; + while(<>) { chomp; - next unless m{^[abcdefilostg]+$}; + next unless m{^[abcdefoilstg]+$}; my $t = $_; my $N = tr/oilstg/011579/; + next if $ACTION eq 'numbers' && $N < length $_; + next if $ACTION eq 'letters' && $N > 0; + next if $ACTION eq '2numbers' && $N > 15; warn "$N\t$t\t$_\n" if $N == length $_; - $words->[length $_]{$N}{$t}=$_; + $words->[length $_]{$N}{$t}="$_ (".hex($_).")"; } print Dumper( $words ); diff --git a/challenge-166/james-smith/perl/ch-2.pl b/challenge-166/james-smith/perl/ch-2.pl index 7fd55bacde..282205633b 100644 --- a/challenge-166/james-smith/perl/ch-2.pl +++ b/challenge-166/james-smith/perl/ch-2.pl @@ -17,6 +17,7 @@ say 'Compact - dir. data'; k( f() ); say ''; say 'Non compact'; z_diff(); say ''; say 'No comments'; z_diff_no_comments(); say ''; say 'Super compact'; z(); say ''; +say 'Super compact'; x(); say ''; ## ## Data produces/fetches @@ -249,12 +250,19 @@ sub z_diff_no_comments { say $HORIZONTAL_LINE; } -## Merging the fetch/parse into the a single function gives us just 369 bytes -## of perlly goodness {362 without the fn call overhead} +## Merging the fetch/parse into the a single function gives us just 357 bytes +## of perlly goodness {350 without the fn call overhead} #23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789# -sub z{my($l,%d,$F,@p,%u,$T,$H)=0;(@_=split/\//),push@{$d{$_[0]}},-d$_?"$_[1]/": -$_[1]for sort<*/*>;$u{$_}++for map{@{$d{$_}}}@p=sort keys%d;length$_>$l?$l= -length:1for@p,keys%u;say for$H=join('-'x($l+2),('+')x(1+@p)),sprintf($T='|'. -" %-${l}s |"x@p,@p),$H,map({$u{$F=$_}<@p?sprintf$T,map{($d{$_}[0]//'')ne$F?'': -shift@{$d{$_}}}@p:map{shift@{$d{$_}};()}@p}sort keys%u),$H} +sub z{my($l,$F,%d,%u,$T,$H)=0;(@_=split'/'),push@{$d{$_[0]}},-d?"$_[1]/":$_[1] +for<*/*>;$u{$_}++for map{@{$d{$_}}}my@p=sort keys%d;$l<length?$l=length:1for@p, +@_=keys%u;say for$H=join('-'x($l+2),('+')x(1+@p)),sprintf($T="| %-${l}s "x@p.'|' +,@p),$H,map({$u{$F=$_}<@p?sprintf$T,map{($d{$_}[0]//'')ne$F?'':shift@{$d{$_}}}@p +:map{shift@{$d{$_}};()}@p}sort@_),$H} + +sub x{my($l,$F,%d,%u,$T,$H)=0;(@_=split'/'),push@{$d{$_[0]}},-d?"$_[1]/":$_[1] +for<*/*>;$u{$_}++for map{@{$d{$_}}}my@p=sort keys%d;$l<length?$l=length:1for@p, +@_=keys%u;say$H=join('-'x($l+2),('+')x@p,'+ +'),sprintf($T="| %-${l}s "x@p.'| +',@p),$H,map({$u{$F=$_}<@p?sprintf$T,map{($d{$_}[0]//'')ne$F?'':shift@{$d{$_}} +}@p:map{shift@{$d{$_}};()}@p}sort@_),$H} |
