diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-06-25 16:25:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-25 16:25:42 +0100 |
| commit | b0dc7de4339cc3ce1fcf72c7f604ee79e0bf2a6d (patch) | |
| tree | cf8a89f90acd341484ca0a6ef72f73613b284597 | |
| parent | cae2ac2271e9b6ab30c60e6405b1ad4adc1c61d2 (diff) | |
| parent | 5587b4398adf6df5c969c068802dfbae1ef5aa27 (diff) | |
| download | perlweeklychallenge-club-b0dc7de4339cc3ce1fcf72c7f604ee79e0bf2a6d.tar.gz perlweeklychallenge-club-b0dc7de4339cc3ce1fcf72c7f604ee79e0bf2a6d.tar.bz2 perlweeklychallenge-club-b0dc7de4339cc3ce1fcf72c7f604ee79e0bf2a6d.zip | |
Merge pull request #302 from jacoby/p14
I Did A Perl6!
| -rwxr-xr-x | challenge-014/dave-jacoby/p014c2.p6 | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/challenge-014/dave-jacoby/p014c2.p6 b/challenge-014/dave-jacoby/p014c2.p6 new file mode 100755 index 0000000000..84a9bd0117 --- /dev/null +++ b/challenge-014/dave-jacoby/p014c2.p6 @@ -0,0 +1,54 @@ +#!/usr/bin/env perl6 + +# My first Perl6 entry! + +# This took a bit. First I had to wipe and redo my rakudobrew, +# because I pull out Perl 6 once every two years or so. Looking +# at Damian Conway's Perl 6 solutions, I can't help but think this +# is "baby perl 6" (which I'm sure Larry would say is okay), but +# there's a command or two that solve everything, as long as you +# throw away decades of mental models to get there. + +# I did a qw{} in Perl 5, but I was afraid and just made the +# array myself here. + + +my %states = map { $_ => 1 } , + "AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA", + "HI","ID","IL","IN","IA","KS","KY","LA","ME","MD", + "MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ", + "NM","NY","NC","ND","OH","OK","OR","PA","RI","SC", + "CD","TN","TX","UT","VT","VA","WA","WV","WI","WY"; + +my @words = '/usr/share/dict/words'.IO.lines; + +# when testing, use a smaller data set +# @words = "PACT","WIND","PERL","CALAMARI"; + +my $longest = ''; +MAIN: for @words -> $word { + my @word = $word ~~ m:g/\w ** 2/; + + my $join = @word.join(''); + next if $join ne $word; + + for @word -> $wo { + my $n = %states{$wo.uc} ?? 1 !! 0; + next MAIN unless $n; + } + + $longest = $word if $longest.chars < $word.chars; + } + +say $longest; + +# the word-list I have here is smaller than the one I have on my +# laptop, so the longest word I have is "Concorde", being +# Colorado +# North Carolina +# Oregon +# Delaware + +# but my Perl 5 version gets the same, so ¯\_(ツ)_/¯ + +# I am disappointed by the speed drop, tho
\ No newline at end of file |
