From 19716bbb7f4f4ed50fba5776b439763d073f8bec Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Mon, 12 Oct 2020 16:25:44 +0800 Subject: challenge 082, raku solution --- challenge-082/feng-chang/raku/ch-1.raku | 5 +++++ challenge-082/feng-chang/raku/ch-2.raku | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 challenge-082/feng-chang/raku/ch-1.raku create mode 100755 challenge-082/feng-chang/raku/ch-2.raku diff --git a/challenge-082/feng-chang/raku/ch-1.raku b/challenge-082/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..7992e918d2 --- /dev/null +++ b/challenge-082/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +sub MAIN(UInt:D $M, UInt:D $N) { + (1..min($M,$N)).grep({ ($M & $N) %% $_ }).say; +} diff --git a/challenge-082/feng-chang/raku/ch-2.raku b/challenge-082/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..cfcc92c4af --- /dev/null +++ b/challenge-082/feng-chang/raku/ch-2.raku @@ -0,0 +1,23 @@ +#!/bin/env raku + +sub interleave-string($a, $b, $c --> UInt) { + if $c.elems == 0 { + return ($a.elems | $b.elems) > 0 ?? 0 !! 1; + } + + return 0 if ($a[0] // '', $b[0] // '').none eq $c[0]; + + if $c[0] eq ($a[0] // '') { + return 1 if interleave-string($a.tail(*-1), $b, $c.tail(*-1)) == 1; + } + + if $c[0] eq ($b[0] // '') { + return interleave-string($a, $b.tail(*-1), $c.tail(*-1)); + } else { + return 0; + } +} + +sub MAIN(Str:D $A, Str:D $B, Str:D $C) { + say interleave-string($A.comb.List, $B.comb.List, $C.comb.List); +} -- cgit