aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-06-14 10:41:50 +0100
committerGitHub <noreply@github.com>2021-06-14 10:41:50 +0100
commit868a2485a546202e08752471287004cfec8f4ba9 (patch)
treea76486065455d294ee844de3b14b9c86edd6fd81
parent074a15e88412b0e5c857383ccfc1d0ac9bc027ee (diff)
parent29562bef8edd547534f220916b3bdc0de1b7e7dd (diff)
downloadperlweeklychallenge-club-868a2485a546202e08752471287004cfec8f4ba9.tar.gz
perlweeklychallenge-club-868a2485a546202e08752471287004cfec8f4ba9.tar.bz2
perlweeklychallenge-club-868a2485a546202e08752471287004cfec8f4ba9.zip
Merge pull request #4253 from seaker/master
Challenge #117, Feng Chang's Raku solutions
-rwxr-xr-xchallenge-116/feng-chang/raku/ch-1.raku18
-rwxr-xr-xchallenge-116/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-117/feng-chang/raku/ch-1.raku10
-rwxr-xr-xchallenge-117/feng-chang/raku/ch-2.raku29
-rw-r--r--challenge-117/feng-chang/raku/input.txt14
5 files changed, 76 insertions, 0 deletions
diff --git a/challenge-116/feng-chang/raku/ch-1.raku b/challenge-116/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..f6191bcb70
--- /dev/null
+++ b/challenge-116/feng-chang/raku/ch-1.raku
@@ -0,0 +1,18 @@
+#!/bin/env raku
+
+sub MAIN(UInt:D $N where * ≥ 10) {
+ for 1 .. $N.chars div 2 -> $len {
+ my $n = $N;
+ my $i = $n.substr(0, $len);
+ while $n.chars > 0 {
+ last unless $n.substr(0, $i.chars) eq $i;
+ $n .= substr($i.chars);
+ ++$i;
+ }
+ if $n.chars == 0 {
+ put 1;
+ exit;
+ }
+ }
+ put 0;
+}
diff --git a/challenge-116/feng-chang/raku/ch-2.raku b/challenge-116/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..8ece4d5102
--- /dev/null
+++ b/challenge-116/feng-chang/raku/ch-2.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+sub MAIN(UInt:D $N where * ≥ 10) {
+ put $N.comb».Int.map(*²).reduce(&infix:<+>).&{ +(sqrt($_).Int² == $_) };
+}
diff --git a/challenge-117/feng-chang/raku/ch-1.raku b/challenge-117/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..15f96ac5e0
--- /dev/null
+++ b/challenge-117/feng-chang/raku/ch-1.raku
@@ -0,0 +1,10 @@
+#!/bin/env raku
+
+sub MAIN(Str:D $f where *.IO.f = 'input.txt') {
+ my Set $nums = (1..15).Set;
+ for $f.IO.lines -> $line {
+ $line ~~ m/^ (\d+)/;
+ $nums (-)= ($0.UInt).Set;
+ }
+ put 'the missing number: ', $nums.keys;
+}
diff --git a/challenge-117/feng-chang/raku/ch-2.raku b/challenge-117/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..cebd4974c3
--- /dev/null
+++ b/challenge-117/feng-chang/raku/ch-2.raku
@@ -0,0 +1,29 @@
+#!/bin/env raku
+
+my Bool $not-first = False;
+
+sub travel(UInt:D $row, UInt:D $col, Str:D $path, UInt:D $target-row, UInt:D $target-col) {
+ if $row == $target-row and $col == $target-col {
+ if $not-first {
+ print ', ';
+ } else {
+ $not-first = True;
+ }
+ print $path;
+ return;
+ }
+
+ # try 'R'
+ travel($row + 1, $col + 1, $path ~ 'R', $target-row, $target-col) if $row < $target-row and $col < $target-col;
+
+ # try 'H'
+ travel($row, $col + 1, $path ~ 'H', $target-row, $target-col) if $col < $row;
+
+ # try 'L'
+ travel($row + 1, $col, $path ~ 'L', $target-row, $target-col) if $row < $target-row;
+}
+
+sub MAIN(UInt:D $n = 10) {
+ travel(0, 0, '', $n, $n);
+ put '';
+}
diff --git a/challenge-117/feng-chang/raku/input.txt b/challenge-117/feng-chang/raku/input.txt
new file mode 100644
index 0000000000..5b9d9ab1ce
--- /dev/null
+++ b/challenge-117/feng-chang/raku/input.txt
@@ -0,0 +1,14 @@
+11, Line Eleven
+1, Line one
+9, Line Nine
+13, Line Thirteen
+2, Line two
+6, Line Six
+8, Line Eight
+10, Line Ten
+7, Line Seven
+4, Line Four
+14, Line Fourteen
+3, Line three
+15, Line Fifteen
+5, Line Five