aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-06-08 15:38:14 +0100
committerGitHub <noreply@github.com>2021-06-08 15:38:14 +0100
commit044b240256b60ea2e966bb578ec26ea60bd4452f (patch)
treebdad65aed577c53a20f98b31efa5cc3f3169ab98
parent4e8cfbc7fd03a526e49e2af7af2b8a8b4acfdf48 (diff)
parent17ae968a18571df8021c1726201d69a025cb98d7 (diff)
downloadperlweeklychallenge-club-044b240256b60ea2e966bb578ec26ea60bd4452f.tar.gz
perlweeklychallenge-club-044b240256b60ea2e966bb578ec26ea60bd4452f.tar.bz2
perlweeklychallenge-club-044b240256b60ea2e966bb578ec26ea60bd4452f.zip
Merge pull request #4220 from stuart-little/stuart-little_116_node
1st commit on 116_node
-rwxr-xr-xchallenge-116/stuart-little/node/ch-1.js13
-rwxr-xr-xchallenge-116/stuart-little/node/ch-2.js6
2 files changed, 19 insertions, 0 deletions
diff --git a/challenge-116/stuart-little/node/ch-1.js b/challenge-116/stuart-little/node/ch-1.js
new file mode 100755
index 0000000000..32f32482f8
--- /dev/null
+++ b/challenge-116/stuart-little/node/ch-1.js
@@ -0,0 +1,13 @@
+#!/usr/bin/env node
+
+// run <script> <number>
+
+function fstRunOver(s1,s2) {
+ return [...Array(s2.length).keys()].map(i => [...Array(i+1).keys()].map(x => x+parseInt(s1))).find(xs => s2.length <= xs.map(x => x.toString().length).reduce((x,y) => x+y))
+}
+
+function consecSplit(s) {
+ return [...Array(s.length).keys()].map(i => s.substr(0,i+1)).map(x => fstRunOver(x,s)).find(xs => xs.join("") === s)
+}
+
+console.log(consecSplit(process.argv[2]))
diff --git a/challenge-116/stuart-little/node/ch-2.js b/challenge-116/stuart-little/node/ch-2.js
new file mode 100755
index 0000000000..8eef71f6d7
--- /dev/null
+++ b/challenge-116/stuart-little/node/ch-2.js
@@ -0,0 +1,6 @@
+#!/usr/bin/env node
+
+// run <script> <number>
+
+const digSqSum=process.argv[2].split('').map(x => parseInt(x) ** 2).reduce((x,y) => x+y)
+console.log(0+(Math.floor(Math.sqrt(digSqSum)) ** 2 == digSqSum))