aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPolgár Márton <polgar@astron.hu>2022-11-18 12:55:15 +0100
committerPolgár Márton <polgar@astron.hu>2022-11-18 12:55:15 +0100
commite31694d51165d53ef95e3c335a0abcc757a16c09 (patch)
tree6d01e064f07f98bdb88ed2e91b1f7358f76958e7
parent3daa061db26124bfb604997752fbcdc791ac6f0e (diff)
downloadperlweeklychallenge-club-e31694d51165d53ef95e3c335a0abcc757a16c09.tar.gz
perlweeklychallenge-club-e31694d51165d53ef95e3c335a0abcc757a16c09.tar.bz2
perlweeklychallenge-club-e31694d51165d53ef95e3c335a0abcc757a16c09.zip
Solutions of week 191 by 2colours
-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;
+}