aboutsummaryrefslogtreecommitdiff
path: root/challenge-141/abigail/node
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-141/abigail/node')
-rw-r--r--challenge-141/abigail/node/ch-1.js30
-rw-r--r--challenge-141/abigail/node/ch-2.js32
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-141/abigail/node/ch-1.js b/challenge-141/abigail/node/ch-1.js
new file mode 100644
index 0000000000..e246fffd08
--- /dev/null
+++ b/challenge-141/abigail/node/ch-1.js
@@ -0,0 +1,30 @@
+#!/usr/local/bin/node
+
+//
+// See ../README.md
+//
+
+//
+// Run as: node ch-1.js
+//
+
+
+let count = 10
+let nr_of_divisors = 8
+
+for (let n = 1; count > 0; n ++) {
+ let s = Math . floor (Math . sqrt (n))
+ if (n == s * s) {
+ continue
+ }
+ let c = 0
+ for (let d = 1; d <= s && c <= nr_of_divisors; d ++) {
+ if (n % d == 0) {
+ c += 2
+ }
+ }
+ if (c == nr_of_divisors) {
+ console . log (n)
+ count --
+ }
+}
diff --git a/challenge-141/abigail/node/ch-2.js b/challenge-141/abigail/node/ch-2.js
new file mode 100644
index 0000000000..53b7b7ac44
--- /dev/null
+++ b/challenge-141/abigail/node/ch-2.js
@@ -0,0 +1,32 @@
+#!/usr/local/bin/node
+
+//
+// See ../README.md
+//
+
+//
+// Run as: node ch-2.js < input-file
+//
+
+function substrings (n, m, prefix, max) {
+ if (n . length == 0) {
+ return prefix > -1 &&
+ prefix < max &&
+ prefix % m == 0 ? 1 : 0
+ }
+
+ let fc = n . substr (0, 1)
+ let tail = n . substr (1)
+ let n_prefix = 10 * (prefix == -1 ? 0 : prefix) + + n . substr (0, 1)
+
+ return substrings (tail, m, n_prefix, max) +
+ substrings (tail, m, prefix, max);
+}
+
+ require ('readline')
+. createInterface ({input: process . stdin})
+. on ('line', line => {
+ let [n, m] = line . split (" ")
+ console . log (substrings (n, +m, -1, +n))
+})
+