diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-06-07 09:34:31 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-06-07 09:34:31 -0400 |
| commit | 17ae968a18571df8021c1726201d69a025cb98d7 (patch) | |
| tree | 70708d72dbaafe06524e07e989415f39d855b103 | |
| parent | 4830b1d50fd610eb2424fe284cb48a2795e0478c (diff) | |
| download | perlweeklychallenge-club-17ae968a18571df8021c1726201d69a025cb98d7.tar.gz perlweeklychallenge-club-17ae968a18571df8021c1726201d69a025cb98d7.tar.bz2 perlweeklychallenge-club-17ae968a18571df8021c1726201d69a025cb98d7.zip | |
1st commit on 116_node
| -rwxr-xr-x | challenge-116/stuart-little/node/ch-1.js | 13 | ||||
| -rwxr-xr-x | challenge-116/stuart-little/node/ch-2.js | 6 |
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)) |
