diff options
| author | 冯昶 <seaker@qq.com> | 2021-09-03 11:20:46 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2021-09-03 11:20:46 +0800 |
| commit | 2f49bb6081fe7aceecc37b213a1e9d6b6e802ca2 (patch) | |
| tree | a67b1059ab3634b381283663753e568304fa1868 | |
| parent | 3cffe71863a81caeb301cdc4f20150ffa82df490 (diff) | |
| download | perlweeklychallenge-club-2f49bb6081fe7aceecc37b213a1e9d6b6e802ca2.tar.gz perlweeklychallenge-club-2f49bb6081fe7aceecc37b213a1e9d6b6e802ca2.tar.bz2 perlweeklychallenge-club-2f49bb6081fe7aceecc37b213a1e9d6b6e802ca2.zip | |
提交本地修改
| -rwxr-xr-x | challenge-126/feng-chang/raku/ch-1.raku | 5 | ||||
| -rwxr-xr-x | challenge-126/feng-chang/raku/ch-2.raku | 22 | ||||
| -rw-r--r-- | challenge-126/feng-chang/raku/input.txt | 5 |
3 files changed, 32 insertions, 0 deletions
diff --git a/challenge-126/feng-chang/raku/ch-1.raku b/challenge-126/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..aa39eff4cb --- /dev/null +++ b/challenge-126/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +sub MAIN(UInt:D $N) { + put (2..$N).grep(!*.comb.grep(1)).elems; +} diff --git a/challenge-126/feng-chang/raku/ch-2.raku b/challenge-126/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..e1dfc70f6e --- /dev/null +++ b/challenge-126/feng-chang/raku/ch-2.raku @@ -0,0 +1,22 @@ +#!/bin/env raku + +sub is-mine(Array:D $game, Int:D $row, Int:D $col, UInt:D $max-row, UInt:D $max-col --> Bool:D) { + return False unless 0 ≤ $row < $max-row; + return False unless 0 ≤ $col < $max-col; + $game[$row;$col] eq 'x' +} + +sub neibours(Array:D $game, UInt:D $row, UInt:D $col --> Str:D) { + $game[$row;$col] eq 'x' ?? 'x' !! ( + ( 1, -1), ( 1, 0), ( 1, 1), + ( 0, -1), ( 0, 1), + (-1, -1), (-1, 0), (-1, 1) + ).map({ is-mine($game, $row + .[0], $col + .[1], $game.elems, $game[0].elems) }).grep(?*).elems.Str +} + +sub MAIN(Str:D $f where $f.IO.e = 'input.txt') { + my Array $game = $f.IO.lines».comb.Array; + for ^$game.elems -> $row { + put (^$game[0].elems).map({ neibours($game, $row, .[0]) }).join(' '); + } +} diff --git a/challenge-126/feng-chang/raku/input.txt b/challenge-126/feng-chang/raku/input.txt new file mode 100644 index 0000000000..c7dd9f6980 --- /dev/null +++ b/challenge-126/feng-chang/raku/input.txt @@ -0,0 +1,5 @@ +x***x*xxxx +*********x +****x*x*x* +***xx***** +x***x****x |
