aboutsummaryrefslogtreecommitdiff
path: root/challenge-102
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-03-09 21:24:25 +0000
committerGitHub <noreply@github.com>2021-03-09 21:24:25 +0000
commit2b892db40d452e98f7a98ad023bed312e2dcbe8b (patch)
treeca90bc2435db9ae78ffc8b21b2a6ee515bc648e9 /challenge-102
parent0490b0e1b8c06e53b0882364f2c70167c7703f95 (diff)
parentc9aec2da6bcb04b488183f09ca94bee488557aff (diff)
downloadperlweeklychallenge-club-2b892db40d452e98f7a98ad023bed312e2dcbe8b.tar.gz
perlweeklychallenge-club-2b892db40d452e98f7a98ad023bed312e2dcbe8b.tar.bz2
perlweeklychallenge-club-2b892db40d452e98f7a98ad023bed312e2dcbe8b.zip
Merge pull request #3698 from seaker/master
challenge #103, FENG Chang's 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;
+}