aboutsummaryrefslogtreecommitdiff
path: root/challenge-102
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2021-03-09 21:26:58 +0800
committer冯昶 <fengchang@novel-supertv.com>2021-03-09 21:26:58 +0800
commitc9aec2da6bcb04b488183f09ca94bee488557aff (patch)
tree5df4891a48e0cb0ea8a9542e6f0c7c4ffc8f13e8 /challenge-102
parentda7e149ecb3abdf29d3fb4f712427217d02f2fe1 (diff)
downloadperlweeklychallenge-club-c9aec2da6bcb04b488183f09ca94bee488557aff.tar.gz
perlweeklychallenge-club-c9aec2da6bcb04b488183f09ca94bee488557aff.tar.bz2
perlweeklychallenge-club-c9aec2da6bcb04b488183f09ca94bee488557aff.zip
challenge #103, raku solutions
Diffstat (limited to 'challenge-102')
-rwxr-xr-xchallenge-102/feng-chang/raku/ch-1.raku17
-rwxr-xr-xchallenge-102/feng-chang/raku/ch-2.raku15
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-102/feng-chang/raku/ch-1.raku b/challenge-102/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..463aa8f413
--- /dev/null
+++ b/challenge-102/feng-chang/raku/ch-1.raku
@@ -0,0 +1,17 @@
+#!/bin/env raku
+
+sub is-square(UInt:D \N --> Bool:D) {
+ my UInt $n = N.sqrt.UInt;
+ N == $n * $n;
+}
+
+sub MAIN(UInt:D \N) {
+ my UInt $min = ('1' ~ '0' x N-1).UInt;
+ my UInt $max = ('9' x N).UInt;
+ for $min..$max -> $m {
+ my UInt $n = $m.flip.UInt;
+ next if $n > $m;
+
+ put $m if is-square($m + $n) and is-square($m - $n);
+ }
+}
diff --git a/challenge-102/feng-chang/raku/ch-2.raku b/challenge-102/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..394fede9ae
--- /dev/null
+++ b/challenge-102/feng-chang/raku/ch-2.raku
@@ -0,0 +1,15 @@
+#!/bin/env raku
+
+sub MAIN(UInt:D \N) {
+ my Str:D $s = '#';
+ my UInt:D $pos = N;
+
+ while $s.chars < N {
+ $s = $pos ~ $s;
+ $pos = N - $s.chars;
+
+ $s = '#' ~ $s if $s.chars < N;
+ }
+
+ put $s;
+}