diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-12-22 23:18:42 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-22 23:18:42 +0000 |
| commit | bb2e75e02cc95d8d35ed86aafce0082502a254dd (patch) | |
| tree | 132250166965d3b134e63c300113ce261462f15c | |
| parent | aba4eedbe80c849f5e62dcfb2d0cc2d02e588640 (diff) | |
| parent | cffcad5b0cf1c1c105e170631c5aa1818b2bbb7d (diff) | |
| download | perlweeklychallenge-club-bb2e75e02cc95d8d35ed86aafce0082502a254dd.tar.gz perlweeklychallenge-club-bb2e75e02cc95d8d35ed86aafce0082502a254dd.tar.bz2 perlweeklychallenge-club-bb2e75e02cc95d8d35ed86aafce0082502a254dd.zip | |
Merge pull request #3042 from stuart-little/stuart-little_038
1st commit on 038
| -rw-r--r-- | challenge-038/stuart-little/README | 1 | ||||
| -rwxr-xr-x | challenge-038/stuart-little/raku/ch-1.p6 | 17 | ||||
| -rwxr-xr-x | challenge-038/stuart-little/raku/ch-2.p6 | 30 |
3 files changed, 48 insertions, 0 deletions
diff --git a/challenge-038/stuart-little/README b/challenge-038/stuart-little/README new file mode 100644 index 0000000000..78439907de --- /dev/null +++ b/challenge-038/stuart-little/README @@ -0,0 +1 @@ +Solutions by Stuart Little diff --git a/challenge-038/stuart-little/raku/ch-1.p6 b/challenge-038/stuart-little/raku/ch-1.p6 new file mode 100755 index 0000000000..7e0ede5fa6 --- /dev/null +++ b/challenge-038/stuart-little/raku/ch-1.p6 @@ -0,0 +1,17 @@ +#!/usr/bin/env perl6 +use v6; + +sub extract_date($str) { + $str ~~ /^(1 || 2) (\d ** 2) ((0(<[1..9]>)) || (1(0 || 1 || 2))) (\d ** 2)/; + + (! $/.[0,1,2,3].all) && return "Malformed date string"; + + my $year=((($/.[0] ~~ 1) ?? ('20') !! ('19')) ~ $/.[1].Str).Int; + my ($month,$day)=$/.[2,3].map(*.Int); + + ($day !~~ 1..(Date.new($year,$month,1).last-date-in-month.day)) && return "Malformed date string"; + + return qq|{$year}-{sprintf("%02d",$month)}-{$day}|; +} + +say extract_date(@*ARGS[0]) diff --git a/challenge-038/stuart-little/raku/ch-2.p6 b/challenge-038/stuart-little/raku/ch-2.p6 new file mode 100755 index 0000000000..210266e3cb --- /dev/null +++ b/challenge-038/stuart-little/raku/ch-2.p6 @@ -0,0 +1,30 @@ +#!/usr/bin/env perl6 +use v6; + +my %*SUB-MAIN-OPTS=:named-anywhere,; +sub MAIN( + Str $dictionary-file, +) { + +my %hash=( + 1 => ('A' xx 8, 'G' xx 3, 'I' xx 5, 'S' xx 7, 'U' xx 5, 'X' xx 2, 'Z' xx 5).flat.Array, + 2 => ('E' xx 9, 'J' xx 3, 'L' xx 3, 'R' xx 3, 'V' xx 3, 'Y' xx 5).flat.Array, + 3 => ('F' xx 3, 'D' xx 3, 'P' xx 5, 'W' xx 5).flat.Array, + 4 => ('B' xx 5, 'N' xx 4).flat.Array, + 5 => ('T' xx 5, 'O' xx 3, 'H' xx 3, 'M' xx 4, 'C' xx 4).flat.Array, + 10 => ('K' xx 2, 'Q' xx 2).flat.Array, +); + +my $freq=%hash.values.map(|*).sort.Bag; +my %pts=('A'..'Z').map({ $_ => %hash.keys.Array.grep( -> $key { %hash{$key}.any eq $_ }).[0] }); + +my @letters=$freq.roll(7); +say "Seven random letters from your bag: ", @letters, "\n"; + +say $dictionary-file.IO.words.grep({ ! ($_.uc.comb.Bag (-) @letters) }).map({ $_, score($_,%pts) }).classify(*.[1]).max(*.[0]); + +} + +sub score($word,%pts) { + $word.uc.comb.map({ %pts{$_} }).sum +} |
