diff options
| author | Simon Proctor <simon.proctor@gmail.com> | 2019-06-28 13:45:10 +0100 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@gmail.com> | 2019-06-28 13:45:10 +0100 |
| commit | 9f3dca54d0fe0d7d98e23618ff72f72e55da8a62 (patch) | |
| tree | 9ed9cd64d56b48f716cde735660142e61da484f5 | |
| parent | d59694947b4f327ef3ea7258385481145bb1b150 (diff) | |
| download | perlweeklychallenge-club-9f3dca54d0fe0d7d98e23618ff72f72e55da8a62.tar.gz perlweeklychallenge-club-9f3dca54d0fe0d7d98e23618ff72f72e55da8a62.tar.bz2 perlweeklychallenge-club-9f3dca54d0fe0d7d98e23618ff72f72e55da8a62.zip | |
Find the longest word made from US state codes
| -rw-r--r-- | challenge-014/simon-proctor/perl6/ch-2.p6 | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-014/simon-proctor/perl6/ch-2.p6 b/challenge-014/simon-proctor/perl6/ch-2.p6 new file mode 100644 index 0000000000..cad8992aa5 --- /dev/null +++ b/challenge-014/simon-proctor/perl6/ch-2.p6 @@ -0,0 +1,26 @@ +#!/usr/bin/env + +use v6; + +subset FilePath of Str where *.IO.f; + +#| Look in the given dictionary for the longest word that can be made from the given dictionary +sub MAIN( + FilePath :$dict = "/etc/dictionaries-common/words" #= Dictionary file to use. Defaults to "/etc/dictionaries-common/words" +) { + my $states = bag( <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 + SD TN TX UT VT VA WA WV WI WY> ); + my $word = ""; + + for $dict.IO.words.grep( *.codes %% 2 ) -> $possible { + my $check = bag( $possible.uc.comb(/../ ) ); + if $states (>=) $check && $possible.codes > $word.codes { + $word = $possible; + } + } + + say $word; +} |
