diff options
| -rwxr-xr-x | challenge-267/feng-chang/raku/ch-1.raku | 5 | ||||
| -rwxr-xr-x | challenge-267/feng-chang/raku/ch-1a.raku | 5 | ||||
| -rwxr-xr-x | challenge-267/feng-chang/raku/ch-2.raku | 17 | ||||
| -rwxr-xr-x | challenge-267/feng-chang/raku/test.raku | 29 |
4 files changed, 56 insertions, 0 deletions
diff --git a/challenge-267/feng-chang/raku/ch-1.raku b/challenge-267/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..a4f10dbc25 --- /dev/null +++ b/challenge-267/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +unit sub MAIN(*@ints); + +put [*] @intsĀ».sign; diff --git a/challenge-267/feng-chang/raku/ch-1a.raku b/challenge-267/feng-chang/raku/ch-1a.raku new file mode 100755 index 0000000000..7518f5cdb9 --- /dev/null +++ b/challenge-267/feng-chang/raku/ch-1a.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +unit sub MAIN(*@ints); + +put @ints.any == 0 ?? 0 !! @ints.grep(*.sign == -1) %% 2 ?? 1 !! -1; diff --git a/challenge-267/feng-chang/raku/ch-2.raku b/challenge-267/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..1c6994a94c --- /dev/null +++ b/challenge-267/feng-chang/raku/ch-2.raku @@ -0,0 +1,17 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $str, *@widths); + +my %widths = 'a'..'z' Z=> @widths; + +my ($lines, $w) X= 0; +for $str.comb -> $c { + $w += %widths{$c}; + if $w > 100 { + ++$lines; + $w = %widths{$c}; + } +} +++$lines if $w > 0; + +put "($lines, $w)"; diff --git a/challenge-267/feng-chang/raku/test.raku b/challenge-267/feng-chang/raku/test.raku new file mode 100755 index 0000000000..101aeda0ee --- /dev/null +++ b/challenge-267/feng-chang/raku/test.raku @@ -0,0 +1,29 @@ +#!/bin/env raku + +# The Weekly Challenge 267 +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, Product Sign +pwc-test './ch-1.raku', '--', <-1 -2 -3 -4 3 2 1>, 1, 'Product Sign: (-1, -2, -3, -4, 3, 2, 1) => 1'; +pwc-test './ch-1.raku', '--', <1 2 0 -2 -1>, 0, 'Product Sign: (1, 2, 0, -2, -1) => 0'; +pwc-test './ch-1.raku', '--', <-1 -1 1 -1 2>, -1, 'Product Sign: (-1, -1, 1, -1, 2) => -1'; + +pwc-test './ch-1a.raku', '--', <-1 -2 -3 -4 3 2 1>, 1, 'Product Sign: (-1, -2, -3, -4, 3, 2, 1) => 1'; +pwc-test './ch-1a.raku', '--', <1 2 0 -2 -1>, 0, 'Product Sign: (1, 2, 0, -2, -1) => 0'; +pwc-test './ch-1a.raku', '--', <-1 -1 1 -1 2>, -1, 'Product Sign: (-1, -1, 1, -1, 2) => -1'; + +# Task 2, Line Counts +pwc-test './ch-2.raku', 'abcdefghijklmnopqrstuvwxyz', 10 xx 26, '(3, 60)', + '$str = "abcdefghijklmnopqrstuvwxyz", @widths = (10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10) => (3,26)'; +pwc-test './ch-2.raku', 'bbbcccdddaaa', 4, 10 xx 25, '(2, 4)', + '$str = "bbbcccdddaaa", @widths = (4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10) => (2,4)', |
