aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-249/barroff/raku/ch-1.p622
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-249/barroff/raku/ch-1.p6 b/challenge-249/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..1e6d049f90
--- /dev/null
+++ b/challenge-249/barroff/raku/ch-1.p6
@@ -0,0 +1,22 @@
+#!/usr/bin/env raku
+
+sub equal-pairs(@nums --> List) {
+ my %number-bag = Bag(@nums);
+ return () if so any(%number-bag.values()) % 2 ≠ 0;
+ my @pairs = map({ Slip(($_, $_) xx (%number-bag{$_} div 2))}, %number-bag.keys);
+ return @pairs;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 2;
+
+ is sort(equal-pairs([3, 2, 3, 2, 2, 2])), ((2, 2), (2, 2), (3, 3)), 'Works for (3, 2, 3, 2, 2, 2)';
+ is equal-pairs([1, 2, 3, 4]), (), 'Works for (1, 2, 3, 4)';
+}
+
+#| Take user provided list like 1 1 2 2 2 3
+multi sub MAIN(*@ints) {
+ say equal-pairs(@ints);
+}