diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-03-06 02:00:45 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-06 02:00:45 +0000 |
| commit | 6d45e72e685c2c303f35f2b583e2622401fe0dd8 (patch) | |
| tree | 6ed9d43fdb415b130bf6d1966173b9f4a378bd73 | |
| parent | 41a06fcc3be0579a6d272a0168d50e0b1e5254ce (diff) | |
| parent | 5ebbc1dfaf52b6a265c643bc633b7394a69fbab1 (diff) | |
| download | perlweeklychallenge-club-6d45e72e685c2c303f35f2b583e2622401fe0dd8.tar.gz perlweeklychallenge-club-6d45e72e685c2c303f35f2b583e2622401fe0dd8.tar.bz2 perlweeklychallenge-club-6d45e72e685c2c303f35f2b583e2622401fe0dd8.zip | |
Merge pull request #7672 from Util/c206
Add TWC 206 solutions by Bruce Gray (Raku only).
| -rw-r--r-- | challenge-206/bruce-gray/raku/ch-1.raku | 19 | ||||
| -rw-r--r-- | challenge-206/bruce-gray/raku/ch-2.raku | 15 |
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-206/bruce-gray/raku/ch-1.raku b/challenge-206/bruce-gray/raku/ch-1.raku new file mode 100644 index 0000000000..71a9fc7d2c --- /dev/null +++ b/challenge-206/bruce-gray/raku/ch-1.raku @@ -0,0 +1,19 @@ +sub task1 (@hhmm --> UInt) { + return @hhmm + .map({ .[0] * 60 + .[1] given .split(':') }) + .combinations(2) + .map({ ( $_, 1440 - $_ ).min given abs [-] .list }) + .min; +} + + +constant @tests = + ( <00:00 23:55 20:00> , 5 ), + ( <01:01 00:50 00:57> , 4 ), + ( <10:10 09:30 09:00 09:55> , 15 ), +; +use Test; +plan +@tests; +for @tests -> ( $in, $expected ) { + is task1($in), $expected; +} diff --git a/challenge-206/bruce-gray/raku/ch-2.raku b/challenge-206/bruce-gray/raku/ch-2.raku new file mode 100644 index 0000000000..8f201f5c43 --- /dev/null +++ b/challenge-206/bruce-gray/raku/ch-2.raku @@ -0,0 +1,15 @@ +sub task2 ( @ns where { .elems %% 2 }--> UInt ) { + # return @ns.permutations.map({ .batch(2)».min.sum }).max; # Brute force + return @ns.sort(+*).batch(2)».[0].sum; # Maximize sum by minimizing the gaps inside each pairing. +} + + +constant @tests = + ( (1,2,3,4), 4 ), + ( (0,2,1,3), 2 ), +; +use Test; +plan +@tests; +for @tests -> ( $in, $expected ) { + is task2($in), $expected; +} |
