From 4acaa7af727c18449670d3167b386f057b9c55bd Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 13 Mar 2023 23:46:12 +0000 Subject: Challenge 208 Solutions (Raku) --- challenge-208/mark-anderson/raku/ch-1.raku | 52 ++++++++++++++++++++++++++++++ challenge-208/mark-anderson/raku/ch-2.raku | 31 ++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 challenge-208/mark-anderson/raku/ch-1.raku create mode 100644 challenge-208/mark-anderson/raku/ch-2.raku diff --git a/challenge-208/mark-anderson/raku/ch-1.raku b/challenge-208/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..d28af6fc98 --- /dev/null +++ b/challenge-208/mark-anderson/raku/ch-1.raku @@ -0,0 +1,52 @@ +#!/usr/bin/env raku +use Test; + +is-deeply(min-index-sum(, ), ("Perl", "Raku"), "Example 1"); + +is-deeply(min-index-sum(, ), (), "Example 2"); + +is-deeply(min-index-sum(, ), ("A",), "Example 3"); + +is-deeply(min-index-sum(, + , + , + , + , +

, + , + , + , + ), ("V",), "10 X 25"); + +is-deeply(min-index-sum(, + , + , + , + , + , + , + , + , +

, + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ), ("D", "E", "W"), "25 X 25"); + +sub min-index-sum(+$a) +{ + my $m := $a>>.antipairs>>.Map; + my $k := ([(&)] $m).keys; + ($k Z=> [Z+] $m>>{$k}).Map.minpairs.Map.keys.sort +} diff --git a/challenge-208/mark-anderson/raku/ch-2.raku b/challenge-208/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..b7cf810067 --- /dev/null +++ b/challenge-208/mark-anderson/raku/ch-2.raku @@ -0,0 +1,31 @@ +#!/usr/bin/env raku +use Algorithm::Diff; +use Test; + +is-deeply duplicate-and-missing(1,2,2,4), (2,3); +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); + +# 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"); + +sub duplicate-and-missing(*@nums) +{ + given @nums + { + my @range = .head .. .head + .end; + flat .repeated, keys @range (-) $_ or -1 + } +} + +sub diff-module(*@nums) +{ + my @range = .head .. .head + .end given @nums; + diff(@nums, @range).comb(/\d+/)[1,3] +} -- cgit From d0992efd24bfc17a029362cecdc4800dbecaec3c Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 13 Mar 2023 23:59:52 +0000 Subject: Challenge 208 Solutions (Raku) --- challenge-208/mark-anderson/raku/ch-1.raku | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/challenge-208/mark-anderson/raku/ch-1.raku b/challenge-208/mark-anderson/raku/ch-1.raku index d28af6fc98..f3f080ea2e 100644 --- a/challenge-208/mark-anderson/raku/ch-1.raku +++ b/challenge-208/mark-anderson/raku/ch-1.raku @@ -1,13 +1,13 @@ #!/usr/bin/env raku use Test; -is-deeply(min-index-sum(, ), ("Perl", "Raku"), "Example 1"); +is-deeply min-index-sum(, ), ("Perl", "Raku"), "Example 1"; -is-deeply(min-index-sum(, ), (), "Example 2"); +is-deeply min-index-sum(, ), (), "Example 2"; -is-deeply(min-index-sum(, ), ("A",), "Example 3"); +is-deeply min-index-sum(, ), ("A",), "Example 3"; -is-deeply(min-index-sum(, +is-deeply min-index-sum(, , , , @@ -16,9 +16,9 @@ is-deeply(min-index-sum(, , , , - ), ("V",), "10 X 25"); + ), ("V",), "10 X 25"; -is-deeply(min-index-sum(, +is-deeply min-index-sum(, , , , @@ -42,7 +42,7 @@ is-deeply(min-index-sum(, , , , - ), ("D", "E", "W"), "25 X 25"); + ), ("D", "E", "W"), "25 X 25"; sub min-index-sum(+$a) { -- cgit From 4eb4fceee746cca3ce78e163eb61961b42805adc Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Tue, 14 Mar 2023 20:34:06 +0000 Subject: Challenge 208 Solutions (Raku) --- challenge-208/mark-anderson/raku/ch-2.raku | 20 ++++++++++++-------- 1 file 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 } -- cgit From 8e5c206909f60833316f94fd95e600e73850e983 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Tue, 14 Mar 2023 23:13:18 +0000 Subject: Challenge 208 Solutions (Raku) --- challenge-208/mark-anderson/raku/ch-2.raku | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/challenge-208/mark-anderson/raku/ch-2.raku b/challenge-208/mark-anderson/raku/ch-2.raku index 36f56f72e2..fa193e2cd0 100644 --- a/challenge-208/mark-anderson/raku/ch-2.raku +++ b/challenge-208/mark-anderson/raku/ch-2.raku @@ -8,15 +8,7 @@ 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); - -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); +is-deeply duplicate-and-missing(3,6,5,6,7,8), (6,4); sub duplicate-and-missing(*@nums) { @@ -26,10 +18,3 @@ sub duplicate-and-missing(*@nums) flat .repeated, keys @range (-) $_ or -1 } } - -sub diff-module(*@nums) -{ - my @range = .head .. .head + .end given @nums; - my $r = diff(@nums, @range).comb(/\d+/)[1,3]; - $r.all.defined ?? $r>>.Int !! -1 -} -- cgit From f7ec28790793e89b81f22c0355e96e41403195ab Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Tue, 14 Mar 2023 23:36:11 +0000 Subject: Challenge 208 Solutions (Raku) --- challenge-208/mark-anderson/raku/ch-2.raku | 1 + 1 file changed, 1 insertion(+) diff --git a/challenge-208/mark-anderson/raku/ch-2.raku b/challenge-208/mark-anderson/raku/ch-2.raku index fa193e2cd0..c2c8ff76ec 100644 --- a/challenge-208/mark-anderson/raku/ch-2.raku +++ b/challenge-208/mark-anderson/raku/ch-2.raku @@ -9,6 +9,7 @@ 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); is-deeply duplicate-and-missing(3,6,5,6,7,8), (6,4); +is-deeply duplicate-and-missing(3,4,5,6,7,3), (3,8); sub duplicate-and-missing(*@nums) { -- cgit From be86ff7f425ddc7f2c569a8ca3ec1d0e276e39a8 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Wed, 15 Mar 2023 11:08:02 +0000 Subject: Challenge 208 Solutions (Raku) --- challenge-208/mark-anderson/raku/ch-1.raku | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/challenge-208/mark-anderson/raku/ch-1.raku b/challenge-208/mark-anderson/raku/ch-1.raku index f3f080ea2e..d1318f5ac3 100644 --- a/challenge-208/mark-anderson/raku/ch-1.raku +++ b/challenge-208/mark-anderson/raku/ch-1.raku @@ -7,6 +7,23 @@ is-deeply min-index-sum(, ), (), "Example 2"; is-deeply min-index-sum(, ), ("A",), "Example 3"; +is-deeply min-index-sum(, + , + , + , + , + , + ), ("B", "D"), "7 X 5"; + +is-deeply min-index-sum(, + , + , + , + , + , + , + ), ("H",), "Uneven"; + is-deeply min-index-sum(, , , @@ -16,7 +33,8 @@ is-deeply min-index-sum(, , , , - ), ("V",), "10 X 25"; + ), ("P",), "10 X 25"; + is-deeply min-index-sum(, , @@ -42,11 +60,11 @@ is-deeply min-index-sum(, , , , - ), ("D", "E", "W"), "25 X 25"; + ), ("P",), "25 X 25"; sub min-index-sum(+$a) { my $m := $a>>.antipairs>>.Map; - my $k := ([(&)] $m).keys; + my $k := ([(&)] $m>>.keys).keys; ($k Z=> [Z+] $m>>{$k}).Map.minpairs.Map.keys.sort } -- cgit From 8694ea6ad1d60bf3cf7b149ec1256a303eb3db12 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Wed, 15 Mar 2023 11:13:11 +0000 Subject: Challenge 208 Solutions (Raku) --- challenge-208/mark-anderson/raku/ch-1.raku | 1 - 1 file changed, 1 deletion(-) diff --git a/challenge-208/mark-anderson/raku/ch-1.raku b/challenge-208/mark-anderson/raku/ch-1.raku index d1318f5ac3..3cfea57dc3 100644 --- a/challenge-208/mark-anderson/raku/ch-1.raku +++ b/challenge-208/mark-anderson/raku/ch-1.raku @@ -35,7 +35,6 @@ is-deeply min-index-sum(, , ), ("P",), "10 X 25"; - is-deeply min-index-sum(, , , -- cgit