aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2023-03-14 20:34:06 +0000
committerMark <53903062+andemark@users.noreply.github.com>2023-03-14 20:34:06 +0000
commit4eb4fceee746cca3ce78e163eb61961b42805adc (patch)
treeb350fbc8a8ea450beab4a157efd507837ee9ff14
parentd0992efd24bfc17a029362cecdc4800dbecaec3c (diff)
downloadperlweeklychallenge-club-4eb4fceee746cca3ce78e163eb61961b42805adc.tar.gz
perlweeklychallenge-club-4eb4fceee746cca3ce78e163eb61961b42805adc.tar.bz2
perlweeklychallenge-club-4eb4fceee746cca3ce78e163eb61961b42805adc.zip
Challenge 208 Solutions (Raku)
-rw-r--r--challenge-208/mark-anderson/raku/ch-2.raku20
1 files changed, 12 insertions, 8 deletions
diff --git a/challenge-208/mark-anderson/raku/ch-2.raku b/challenge-208/mark-anderson/raku/ch-2.raku
index b7cf810067..36f56f72e2 100644
--- a/challenge-208/mark-anderson/raku/ch-2.raku
+++ b/challenge-208/mark-anderson/raku/ch-2.raku
@@ -1,5 +1,4 @@
#!/usr/bin/env raku
-use Algorithm::Diff;
use Test;
is-deeply duplicate-and-missing(1,2,2,4), (2,3);
@@ -7,13 +6,17 @@ is-deeply duplicate-and-missing(1,2,3,4), -1;
is-deeply duplicate-and-missing(1,2,3,3), (3,4);
is-deeply duplicate-and-missing(4,5,6,7,7,8), (7,9);
is-deeply duplicate-and-missing(4,5,6,7,7,9), (7,8);
+is-deeply duplicate-and-missing(4,5,6,6,7,9), (6,8);
+is-deeply duplicate-and-missing(4,6,6,7,8,9), (6,5);
-# Algorithm::Diff
-is-deeply diff-module(1,2,2,4), ("2", "3");
-is-deeply diff-module(1,2,3,4), (Nil, Nil);
-is-deeply diff-module(1,2,3,3), ("3", "4");
-is-deeply diff-module(4,5,6,7,7,8), ("7", "9");
-is-deeply diff-module(4,5,6,7,7,9), ("7", "8");
+use Algorithm::Diff;
+is-deeply diff-module(1,2,2,4), (2,3);
+is-deeply diff-module(1,2,3,4), -1;
+is-deeply diff-module(1,2,3,3), (3,4);
+is-deeply diff-module(4,5,6,7,7,8), (7,9);
+is-deeply diff-module(4,5,6,7,7,9), (7,8);
+is-deeply diff-module(4,5,6,6,7,9), (6,8);
+is-deeply diff-module(4,6,6,7,8,9), (6,5);
sub duplicate-and-missing(*@nums)
{
@@ -27,5 +30,6 @@ sub duplicate-and-missing(*@nums)
sub diff-module(*@nums)
{
my @range = .head .. .head + .end given @nums;
- diff(@nums, @range).comb(/\d+/)[1,3]
+ my $r = diff(@nums, @range).comb(/\d+/)[1,3];
+ $r.all.defined ?? $r>>.Int !! -1
}