diff options
Diffstat (limited to 'challenge-262')
| -rwxr-xr-x | challenge-262/feng-chang/raku/ch-1.raku | 6 | ||||
| -rwxr-xr-x | challenge-262/feng-chang/raku/ch-1a.raku | 8 | ||||
| -rwxr-xr-x | challenge-262/feng-chang/raku/ch-2.raku | 6 | ||||
| -rwxr-xr-x | challenge-262/feng-chang/raku/test.raku | 27 |
4 files changed, 47 insertions, 0 deletions
diff --git a/challenge-262/feng-chang/raku/ch-1.raku b/challenge-262/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..e1b106e464 --- /dev/null +++ b/challenge-262/feng-chang/raku/ch-1.raku @@ -0,0 +1,6 @@ +#!/bin/env raku + +unit sub MAIN(*@ints); + +my \posis = +@ints.grep(*>0); +put max(posis, +@ints - posis); diff --git a/challenge-262/feng-chang/raku/ch-1a.raku b/challenge-262/feng-chang/raku/ch-1a.raku new file mode 100755 index 0000000000..4b0b8f4ea7 --- /dev/null +++ b/challenge-262/feng-chang/raku/ch-1a.raku @@ -0,0 +1,8 @@ +#!/bin/env raku + +unit sub MAIN(*@ints); + +@ints ==> +grep(* > 0) ==> +my @v; max(+@v, +@ints - +@v) ==> +put() diff --git a/challenge-262/feng-chang/raku/ch-2.raku b/challenge-262/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..97972e706b --- /dev/null +++ b/challenge-262/feng-chang/raku/ch-2.raku @@ -0,0 +1,6 @@ +#!/bin/env raku + +unit sub MAIN(*@ints); + +my \k = @ints.pop; +put +(^+@ints).combinations(2).grep(-> (\a,\b) { @ints[a] == @ints[b] and a*b %% k }); diff --git a/challenge-262/feng-chang/raku/test.raku b/challenge-262/feng-chang/raku/test.raku new file mode 100755 index 0000000000..6492833931 --- /dev/null +++ b/challenge-262/feng-chang/raku/test.raku @@ -0,0 +1,27 @@ +#!/bin/env raku + +# The Weekly Challenge 262 +use Test; + +sub pwc-test(Str:D $script, Bool :$deeply? = False, *@input) { + my ($expect, $assertion) = @input.splice(*-2, 2); + my $p = run $script, |@input, :out; + if $deeply { + is-deeply $p.out.slurp(:close).chomp.words.Bag, $expect, $assertion; + } else { + is $p.out.slurp(:close).chomp, $expect, $assertion; + } +} + +# Task 1, Max Positive Negative +pwc-test './ch-1.raku', <-- -3 1 2 -1 3 -2 4>, 4, 'Max Positive Negative: (-3,1,2,-1,3,-2,4) => 4'; +pwc-test './ch-1.raku', <-- -1 -2 -3 1>, 3, 'Max Positive Negative: (-1,-2,-3,1) => 3'; +pwc-test './ch-1.raku', <-- 1 2>, 2, 'Max Positive Negative: (1,2) => 2'; + +pwc-test './ch-1a.raku', <-- -3 1 2 -1 3 -2 4>, 4, 'Max Positive Negative: (-3,1,2,-1,3,-2,4) => 4'; +pwc-test './ch-1a.raku', <-- -1 -2 -3 1>, 3, 'Max Positive Negative: (-1,-2,-3,1) => 3'; +pwc-test './ch-1a.raku', <-- 1 2>, 2, 'Max Positive Negative: (1,2) => 2'; + +# Task 2, Count Equal Divisible +pwc-test './ch-2.raku', <3 1 2 2 2 1 3>, 2, 4, 'Count Equal Divisible: @ints=(3,1,2,2,2,1,3), $k=2 => 4'; +pwc-test './ch-2.raku', <1 2 3>, 1, 0, 'Count Equal Divisible: @ints=(1,2,3), $k=1 => 0'; |
