diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2025-10-27 18:34:42 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2025-10-27 18:34:42 +0800 |
| commit | 9301c8908adf6fd6f510ed0dea19611a12eab98a (patch) | |
| tree | 776c48fb9d9ffb2c8ca62a9625a75d73162f4abc | |
| parent | 9b1eba54d5e59d05df44f336120a6a03be62a645 (diff) | |
| download | perlweeklychallenge-club-9301c8908adf6fd6f510ed0dea19611a12eab98a.tar.gz perlweeklychallenge-club-9301c8908adf6fd6f510ed0dea19611a12eab98a.tar.bz2 perlweeklychallenge-club-9301c8908adf6fd6f510ed0dea19611a12eab98a.zip | |
challenge 345, raku solutions
| -rwxr-xr-x | challenge-345/feng-chang/raku/ch-1.raku | 5 | ||||
| -rwxr-xr-x | challenge-345/feng-chang/raku/ch-2.raku | 10 | ||||
| -rwxr-xr-x | challenge-345/feng-chang/raku/test.raku | 28 |
3 files changed, 43 insertions, 0 deletions
diff --git a/challenge-345/feng-chang/raku/ch-1.raku b/challenge-345/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..424d67ee05 --- /dev/null +++ b/challenge-345/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +unit sub MAIN(*@ints); + +put do { +$_ ?? $_ !! 0 } with (1..+@ints-2).grep({ @ints[$_] > (@ints[$_-1], @ints[$_+1]).all }); diff --git a/challenge-345/feng-chang/raku/ch-2.raku b/challenge-345/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..7b9483cbbe --- /dev/null +++ b/challenge-345/feng-chang/raku/ch-2.raku @@ -0,0 +1,10 @@ +#!/bin/env raku + +unit sub MAIN(*@ints); + +my ($cnt, @seen, @ans); +for @ints { + when $_ > 0 { @seen.unshift($_); $cnt = 0; } + when -1 { @ans.push(@seen[$cnt++] // -1); } +} +put @ans; diff --git a/challenge-345/feng-chang/raku/test.raku b/challenge-345/feng-chang/raku/test.raku new file mode 100755 index 0000000000..551942d7c9 --- /dev/null +++ b/challenge-345/feng-chang/raku/test.raku @@ -0,0 +1,28 @@ +#!/bin/env raku + +# The Weekly Challenge 345 +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, Peak Positions +pwc-test './ch-1.raku', <1 3 2>, '1', 'Peak Positions: (1,3,2) => 1'; +pwc-test './ch-1.raku', <2 4 6 5 3>, '2', 'Peak Positions: (2,4,6,5,3) => 2'; +pwc-test './ch-1.raku', <1 2 3 2 4 1>, '2 4', 'Peak Positions: (1,2,3,2,4,1) => 2,4'; +pwc-test './ch-1.raku', <5 3 1>, '0', 'Peak Positions: (5,3,1) => 0'; +pwc-test './ch-1.raku', <1 5 1 5 1 5 1>, '1 3 5', 'Peak Positions: (1,5,1,5,1,5,1) => 1,3,5'; + +# Task 2, Last Visitor +pwc-test './ch-2.raku', <5 -1 -1>, '5 -1', 'Last Visitor: 5,-1,-1 => 5,-1'; +pwc-test './ch-2.raku', <3 7 -1 -1 -1>, '7 3 -1', 'Last Visitor: 3,7,-1,-1,-1 => 7,3,-1'; +pwc-test './ch-2.raku', <2 -1 4 -1 -1>, '2 4 2', 'Last Visitor: 2,-1,4,-1,-1 => 2,4,2'; +pwc-test './ch-2.raku', <10 20 -1 30 -1 -1>, '20 30 20', 'Last Visitor: 10,20,-1,30,-1,-1 => 20,30,20'; +pwc-test './ch-2.raku', <-- -1 -1 5 -1>, '-1 -1 5', 'Last Visitor: -1,-1,5,-1 => -1,-1,5'; |
