aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-06-28 19:11:20 +0100
committerGitHub <noreply@github.com>2019-06-28 19:11:20 +0100
commit030a82dde8223ac9e2d0bcfb8994cf1e38fa3fd8 (patch)
tree6adf5f02dc3b87639237d1bad78aa983cb6166e3
parentc439c469ee89668fe75641c6057701e0071fadb7 (diff)
parent9f3dca54d0fe0d7d98e23618ff72f72e55da8a62 (diff)
downloadperlweeklychallenge-club-030a82dde8223ac9e2d0bcfb8994cf1e38fa3fd8.tar.gz
perlweeklychallenge-club-030a82dde8223ac9e2d0bcfb8994cf1e38fa3fd8.tar.bz2
perlweeklychallenge-club-030a82dde8223ac9e2d0bcfb8994cf1e38fa3fd8.zip
Merge pull request #311 from Scimon/master
Find the longest word made from US state codes
-rw-r--r--challenge-014/simon-proctor/perl6/ch-2.p626
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;
+}