From b2da8f13e1faaedfb3a704d5686c5c813f3cfed4 Mon Sep 17 00:00:00 2001 From: Daniel Mita Date: Sat, 14 Dec 2019 23:48:43 +0000 Subject: Tweaks and documentation --- challenge-038/daniel-mita/perl6/ch-1.p6 | 2 +- challenge-038/daniel-mita/perl6/ch-2.p6 | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/challenge-038/daniel-mita/perl6/ch-1.p6 b/challenge-038/daniel-mita/perl6/ch-1.p6 index 9dcb6fd80c..8b8524b202 100755 --- a/challenge-038/daniel-mita/perl6/ch-1.p6 +++ b/challenge-038/daniel-mita/perl6/ch-1.p6 @@ -8,7 +8,7 @@ my token date-number { } sub MAIN( - $number where * ~~ &date-number, + $number where * ~~ &date-number, #= 7 digit number starting with 1 or 2 followed by YYMMDD --> Nil ) { given $0[0] { diff --git a/challenge-038/daniel-mita/perl6/ch-2.p6 b/challenge-038/daniel-mita/perl6/ch-2.p6 index 1e0654e4f7..4fc759580e 100755 --- a/challenge-038/daniel-mita/perl6/ch-2.p6 +++ b/challenge-038/daniel-mita/perl6/ch-2.p6 @@ -19,18 +19,27 @@ constant %tiles = ( :5Y, :5Z, ).Bag; -sub MAIN (--> Nil) { - given %tiles.pick(7).Bag -> %picked { +#| Find the highest scoring SOWPODS word for a given number of tiles +sub MAIN ( + Int $amount where * > 0 = 7, #= Number of tiles to pick (default: 7) + --> Nil +) { + given %tiles.pick($amount).Bag -> %picked { "Tiles: %picked.kxxv.join()".say; # source: https://www.wordgamedictionary.com/sowpods/download/sowpods.txt "Winner: $_.key() for $_.value()".say with $?FILE.IO.parent.add('sowpods.txt').slurp.uc.words - .grep({ .chars ≤ %picked.elems && .comb ⊆ %picked }) + .grep({ .chars ≤ $amount && .comb ⊆ %picked }) .map(sub { given $^a => $a.comb.map({ %values{$_} }).sum { - .say; + sprintf("%-{$amount}s: %u", |.kv).say; .return; } - }).sort({ $^b.value <=> $^a.value }).first; + }).sort({ + given $^b.value <=> $^a.value { + when Same { $a.key.chars <=> $b.key.chars } + default { $_ } + } + }).first; } } -- cgit