From 9f3dca54d0fe0d7d98e23618ff72f72e55da8a62 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Fri, 28 Jun 2019 13:45:10 +0100 Subject: Find the longest word made from US state codes --- challenge-014/simon-proctor/perl6/ch-2.p6 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 challenge-014/simon-proctor/perl6/ch-2.p6 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( ); + 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; +} -- cgit