diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2024-03-25 17:29:07 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2024-03-25 17:29:07 +0800 |
| commit | 67fef37926d79624e95d5dcf24d7457eb9c38ca9 (patch) | |
| tree | 39d8fd2925d8bafa600cefa4b03138d06ab7d388 /challenge-262 | |
| parent | 041fe9129e3ef4d86df461a0feeee1b3740d5758 (diff) | |
| download | perlweeklychallenge-club-67fef37926d79624e95d5dcf24d7457eb9c38ca9.tar.gz perlweeklychallenge-club-67fef37926d79624e95d5dcf24d7457eb9c38ca9.tar.bz2 perlweeklychallenge-club-67fef37926d79624e95d5dcf24d7457eb9c38ca9.zip | |
challenge 262, raku solutions
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'; |
