diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-08-07 16:19:28 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-08-07 16:19:28 +0800 |
| commit | 0462e0b7406154f2daad93d84648d65a945b9458 (patch) | |
| tree | f608c196d6981c3ba55e7ddba25193008dc283ab | |
| parent | 6ef46b171c093a7fc72e6b52662b9020fe71753a (diff) | |
| download | perlweeklychallenge-club-0462e0b7406154f2daad93d84648d65a945b9458.tar.gz perlweeklychallenge-club-0462e0b7406154f2daad93d84648d65a945b9458.tar.bz2 perlweeklychallenge-club-0462e0b7406154f2daad93d84648d65a945b9458.zip | |
challenge 229, raku solutions
| -rwxr-xr-x | challenge-229/feng-chang/raku/ch-1.raku | 11 | ||||
| -rwxr-xr-x | challenge-229/feng-chang/raku/ch-2.raku | 10 | ||||
| -rw-r--r-- | challenge-229/feng-chang/raku/data01.txt | 3 | ||||
| -rw-r--r-- | challenge-229/feng-chang/raku/data02.txt | 3 | ||||
| -rwxr-xr-x | challenge-229/feng-chang/raku/test.raku | 20 |
5 files changed, 47 insertions, 0 deletions
diff --git a/challenge-229/feng-chang/raku/ch-1.raku b/challenge-229/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..38d6febd42 --- /dev/null +++ b/challenge-229/feng-chang/raku/ch-1.raku @@ -0,0 +1,11 @@ +#!/bin/env raku + +unit sub MAIN(*@S); + +my $cnt; +for @S -> $s { + my @a = $s.comb; + my @b = (1..^+@a).map(-> $j { (@a[$j].ord - @a[$j-1].ord).sign }).unique; + ++$cnt if +@b !== 1 or @b[0] !== 1|-1; +} +put $cnt; diff --git a/challenge-229/feng-chang/raku/ch-2.raku b/challenge-229/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..fec779cf5b --- /dev/null +++ b/challenge-229/feng-chang/raku/ch-2.raku @@ -0,0 +1,10 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $f where *.IO.f); + +my @array = $f.IO.lines.map({ .words».Int }); + +my Set $s1 = @array[0] (&) @array[1]; +my Set $s2 = @array[1] (&) @array[2]; +my Set $s3 = @array[2] (&) @array[0]; +put ($s1 (|) $s2 (|) $s3).keys.sort; diff --git a/challenge-229/feng-chang/raku/data01.txt b/challenge-229/feng-chang/raku/data01.txt new file mode 100644 index 0000000000..c96101a669 --- /dev/null +++ b/challenge-229/feng-chang/raku/data01.txt @@ -0,0 +1,3 @@ +1 1 2 4 +2 4 +4 diff --git a/challenge-229/feng-chang/raku/data02.txt b/challenge-229/feng-chang/raku/data02.txt new file mode 100644 index 0000000000..0dd165038c --- /dev/null +++ b/challenge-229/feng-chang/raku/data02.txt @@ -0,0 +1,3 @@ +4 1 +2 4 +1 2 diff --git a/challenge-229/feng-chang/raku/test.raku b/challenge-229/feng-chang/raku/test.raku new file mode 100755 index 0000000000..5cd217c3a9 --- /dev/null +++ b/challenge-229/feng-chang/raku/test.raku @@ -0,0 +1,20 @@ +#!/bin/env raku + +# The Weekly Challenge 229 +use Test; + +sub pwc-test(Str:D $script, *@input) { + my ($expect, $assertion) = @input.splice(*-2, 2); + my $p = run $script, |@input, :out; + is $p.out.slurp(:close).chomp, $expect, $assertion; +} + +# Task 1, Lexicographic Order +pwc-test './ch-1.raku', |<abc bce cae>, 1, 'Lexicographic Order: ("abc", "bce", "cae") => 1'; +pwc-test './ch-1.raku', |<yxz cba mon>, 2, 'Lexicographic Order: ("yxz", "cba", "mon") => 2'; + +# Task 2, Two out of Three +pwc-test './ch-2.raku', 'data01.txt', '2 4', 'Two out of Three: data01.txt => 2, 4'; +pwc-test './ch-2.raku', 'data02.txt', '1 2 4', 'Two out of Three: data02.txt => 1, 2, 4'; + +done-testing; |
