diff options
| author | Util <bruce.gray@acm.org> | 2023-03-05 15:05:11 -0600 |
|---|---|---|
| committer | Util <bruce.gray@acm.org> | 2023-03-05 15:05:11 -0600 |
| commit | 5ebbc1dfaf52b6a265c643bc633b7394a69fbab1 (patch) | |
| tree | 10e3ba46d8cd2967019c49edb3fd1b7bef3e3771 | |
| parent | b8a8e4a6f319b191d5d38786fd7c55eda14a6575 (diff) | |
| download | perlweeklychallenge-club-5ebbc1dfaf52b6a265c643bc633b7394a69fbab1.tar.gz perlweeklychallenge-club-5ebbc1dfaf52b6a265c643bc633b7394a69fbab1.tar.bz2 perlweeklychallenge-club-5ebbc1dfaf52b6a265c643bc633b7394a69fbab1.zip | |
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; +} |
