aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-191/2colours/raku/ch-1.raku17
-rwxr-xr-xchallenge-191/2colours/raku/ch-2.raku30
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-191/2colours/raku/ch-1.raku b/challenge-191/2colours/raku/ch-1.raku
new file mode 100755
index 0000000000..3ea1f2c6c5
--- /dev/null
+++ b/challenge-191/2colours/raku/ch-1.raku
@@ -0,0 +1,17 @@
+#!/usr/bin/env raku
+
+
+my rule integer { 0 | '-'? <[1..9]> <[0..9]>* };
+subset IntList of Str where /^ '(' <integer>* % [\s* ',' \s*] ')' $/;
+
+
+sub MAIN($input) {
+ die 'Please provide a valid integer list as input.' unless $input ~~ IntList;
+ my @list <==
+ $<integer>
+ .map: *.Int;
+ my $biggest = @list.max;
+ my $second = @list.grep(* != $biggest).max;
+ $biggest >= 2 * $second ?? 1 !! -1 andthen
+ .say;
+} \ No newline at end of file
diff --git a/challenge-191/2colours/raku/ch-2.raku b/challenge-191/2colours/raku/ch-2.raku
new file mode 100755
index 0000000000..dcf7553f83
--- /dev/null
+++ b/challenge-191/2colours/raku/ch-2.raku
@@ -0,0 +1,30 @@
+#!/usr/bin/env raku
+
+constant $limit = 15;
+subset ValidInt of Int where 0 < * <= $limit;
+sub generate-options(ValidInt $n) {
+ ($_ => (1 .. $n).grep(-> $i { $i %% $_ || $_ %% $i }).Set for 1 .. $n)
+}
+
+proto count-cutes(%) {*}
+multi count-cutes(% () --> 1) {}
+multi count-cutes(%options-left) {
+ my ($picked-position, $picked-choices) = %options-left.min(*.value.elems).kv;
+ $picked-choices
+ .keys
+ .map: -> $current-choice {
+ my %options-left-updated = %options-left;
+ %options-left-updated{$picked-position}:delete;
+ %options-left-updated.values X(-)= $current-choice;
+ samewith %options-left-updated
+ } andthen
+ .sum
+}
+
+
+sub MAIN(ValidInt $n) {
+ my %current-options = generate-options $n;
+ %current-options andthen
+ .&count-cutes
+ .say;
+}