diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-11-19 10:18:20 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-19 10:18:20 +0000 |
| commit | 612b0f49c0cde9b2c7c8d9101e7b48eb5160a857 (patch) | |
| tree | 7fe8da600c31bdf38048205874ec5cead9a359fd | |
| parent | 8a84f7097d41e46b04a969c5740b9d197e6e9a09 (diff) | |
| parent | e31694d51165d53ef95e3c335a0abcc757a16c09 (diff) | |
| download | perlweeklychallenge-club-612b0f49c0cde9b2c7c8d9101e7b48eb5160a857.tar.gz perlweeklychallenge-club-612b0f49c0cde9b2c7c8d9101e7b48eb5160a857.tar.bz2 perlweeklychallenge-club-612b0f49c0cde9b2c7c8d9101e7b48eb5160a857.zip | |
Merge pull request #7106 from 2colours/branch-for-challenge-191
Solutions of week 191 by 2colours
| -rwxr-xr-x | challenge-191/2colours/raku/ch-1.raku | 17 | ||||
| -rwxr-xr-x | challenge-191/2colours/raku/ch-2.raku | 30 |
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; +} |
