diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2022-11-20 14:22:01 -0500 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2022-11-20 14:22:01 -0500 |
| commit | dd682dfee966fe63cbfbbbf6a9cb903b1d831416 (patch) | |
| tree | a71619e10c8dcd29fc13a08beb1325f4a7bc5a84 /challenge-191 | |
| parent | d6d01468fd7a5647b9ba96ebf7a0157ff79f3352 (diff) | |
| parent | bde0adaf7b8dfe99c4e494c932d8702eb8cf9a56 (diff) | |
| download | perlweeklychallenge-club-dd682dfee966fe63cbfbbbf6a9cb903b1d831416.tar.gz perlweeklychallenge-club-dd682dfee966fe63cbfbbbf6a9cb903b1d831416.tar.bz2 perlweeklychallenge-club-dd682dfee966fe63cbfbbbf6a9cb903b1d831416.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-191')
115 files changed, 5023 insertions, 95 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; +} diff --git a/challenge-191/LoneWolfiNTj/perl/ch-1.pl b/challenge-191/LoneWolfiNTj/perl/ch-1.pl new file mode 100755 index 0000000000..9319b636f3 --- /dev/null +++ b/challenge-191/LoneWolfiNTj/perl/ch-1.pl @@ -0,0 +1,50 @@ +#! /usr/bin/perl +# PWCC 191 P1: "Twice Largest" + +=pod + +Task 1: Twice Largest +Submitted by: Mohammad S Anwar + +You are given list of integers, @list. + +Write a script to find out whether the largest item in the list +is at least twice as large as each of the other items. + +Example 1 Example 2 +Input: |
