aboutsummaryrefslogtreecommitdiff
path: root/challenge-113/stuart-little/node/ch-1.js
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-05-17 21:58:03 -0400
committerchirvasitua <stuart-little@users.noreply.github.com>2021-05-17 23:45:15 -0400
commita2ff7b545c1f1dce06040fd3954876c2e8cb49bf (patch)
tree4162ac6dd0f6545f89a091d9b0a7ab8df69e0652 /challenge-113/stuart-little/node/ch-1.js
parentc3cd45087006d3f63b05219b8280a25dc1ea7ba9 (diff)
downloadperlweeklychallenge-club-a2ff7b545c1f1dce06040fd3954876c2e8cb49bf.tar.gz
perlweeklychallenge-club-a2ff7b545c1f1dce06040fd3954876c2e8cb49bf.tar.bz2
perlweeklychallenge-club-a2ff7b545c1f1dce06040fd3954876c2e8cb49bf.zip
1st commit on 113_node
Diffstat (limited to 'challenge-113/stuart-little/node/ch-1.js')
-rwxr-xr-xchallenge-113/stuart-little/node/ch-1.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-113/stuart-little/node/ch-1.js b/challenge-113/stuart-little/node/ch-1.js
new file mode 100755
index 0000000000..319423ece6
--- /dev/null
+++ b/challenge-113/stuart-little/node/ch-1.js
@@ -0,0 +1,20 @@
+#!/usr/bin/env node
+
+// run <script> <digit>
+
+function lastDigSumm(nr, dig, nrSummands) {
+ return ((nr - nrSummands * dig) % 10 == 0) && (nrSummands * dig <= nr) && (nrSummands * ((dig -1) * 10 + dig) >= nr)
+}
+
+function lastDig(nr,dig) {
+ return [...Array(9)].map((_,i) => i+1).filter(x => lastDigSumm(nr,dig,x)).length >= 1
+}
+
+function sol(nr,dig) {
+ if (dig == 0) {
+ return (nr >= 101 || (nr % 10 == 0))
+ }
+ return ((nr >= dig * 11) || lastDig(nr,dig))
+}
+
+console.log(sol(...process.argv.slice(2).map(x => parseInt(x))) ? 1 : 0)