diff options
| author | 冯昶 <seaker@qq.com> | 2020-06-15 18:37:38 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2020-06-15 18:37:38 +0800 |
| commit | 435e1df337412ba819adb78930d12e7298f17277 (patch) | |
| tree | fce323b58594099e06b8c306e9519e024769ffd7 | |
| parent | 64956967c39008fbc43dfc63a944153cb0b14e51 (diff) | |
| download | perlweeklychallenge-club-435e1df337412ba819adb78930d12e7298f17277.tar.gz perlweeklychallenge-club-435e1df337412ba819adb78930d12e7298f17277.tar.bz2 perlweeklychallenge-club-435e1df337412ba819adb78930d12e7298f17277.zip | |
raku solution
| -rwxr-xr-x | challenge-064/feng-chang/raku/ch-1.raku | 34 | ||||
| -rwxr-xr-x | challenge-064/feng-chang/raku/ch-2.raku | 27 |
2 files changed, 61 insertions, 0 deletions
diff --git a/challenge-064/feng-chang/raku/ch-1.raku b/challenge-064/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..9f1add1f31 --- /dev/null +++ b/challenge-064/feng-chang/raku/ch-1.raku @@ -0,0 +1,34 @@ +#!/bin/env raku + +my Int $M = prompt 'm: '; +my Int $N = prompt 'n: '; + +my @a; +for $*IN.lines() -> $line { + @a.append($line.comb(/(\d+)/)); + last if @a.elems ≥ $M * $N; +} + +my Int @Mat[$M;$N]; +for ^$M -> Int $i { + for ^$N -> Int $j { + @Mat[$i;$j] = @a.shift.Int; + } +} + +my @Path[$M;$N]; +@Path[0;0] = [@Mat[0;0]]; + +for 1 .. $M + $N - 2 -> Int $s { + for (0, $s - $N + 1).max .. ($s, $M - 1).min -> Int $i { + my Int $j = $s - $i; + + ($i > 0 ?? [+] @Path[$i-1;$j] !! ∞) < ($j > 0 ?? [+] @Path[$i;$j-1] !! ∞) ?? + (@Path[$i;$j] = @Path[$i-1;$j].clone) !! + (@Path[$i;$j] = @Path[$i;$j-1].clone); + + @Path[$i;$j].append(@Mat[$i;$j]); + } +} + +say "{ [+] @Path[$M-1;$N-1] } ({ @Path[$M-1;$N-1].join(' -> ') })"; diff --git a/challenge-064/feng-chang/raku/ch-2.raku b/challenge-064/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..efc38f477e --- /dev/null +++ b/challenge-064/feng-chang/raku/ch-2.raku @@ -0,0 +1,27 @@ +#!/bin/env raku + +wrapper('perlweeklychallenge', <weekly challenge perl>); +wrapper('perlandraku', <python ruby haskell>); + +sub wrapper(Str:D $S, @W) { + my @w = @W.sort({ $^a.chars < $^b.chars }); + my @res; + + my Bool $found-match = False; + split-into($S, @w, @res); + say 'no match' unless $found-match; + + sub split-into(Str:D $S, @W, @R) { + if $S eq '' { + say @R; + $found-match = True; + return; + } + + for @W -> Str $word { + next unless $S.starts-with($word); + + split-into($S.subst(/^$word/), @W, @R.push($word)); + } + } +} |
