aboutsummaryrefslogtreecommitdiff
path: root/challenge-003/abigail/node
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-003/abigail/node')
-rw-r--r--challenge-003/abigail/node/ch-1.js29
-rw-r--r--challenge-003/abigail/node/ch-2.js2
2 files changed, 20 insertions, 11 deletions
diff --git a/challenge-003/abigail/node/ch-1.js b/challenge-003/abigail/node/ch-1.js
index a1ffe969ac..e44318f34c 100644
--- a/challenge-003/abigail/node/ch-1.js
+++ b/challenge-003/abigail/node/ch-1.js
@@ -1,21 +1,30 @@
#!/usr/local/bin/node
//
-// See ../README.md
+// See https://theweeklychallenge.org/blog/perl-weekly-challenge-003
//
//
// Run as: node ch-1.js < input-file
//
-require ('readline')
+let ugly = [1]
+let next_2 = 0
+let next_3 = 0
+let next_5 = 0
+
+ require ('readline')
. createInterface ({input: process . stdin})
-. on ('line', max => {
- for (let base2 = 1; base2 <= max; base2 *= 2) {
- for (let base3 = base2; base3 <= max; base3 *= 3) {
- for (let base5 = base3; base5 <= max; base5 *= 5) {
- console . log (base5)
- }
- }
+. on ('line', n => {
+ n =+ n
+ while (ugly . length < n) {
+ ugly . push (Math . min (2 * ugly [next_2],
+ 3 * ugly [next_3],
+ 5 * ugly [next_5]))
+
+ if (2 * ugly [next_2] <= ugly [ugly . length - 1]) {next_2 ++}
+ if (3 * ugly [next_3] <= ugly [ugly . length - 1]) {next_3 ++}
+ if (5 * ugly [next_5] <= ugly [ugly . length - 1]) {next_5 ++}
}
-});
+ console . log (ugly [n - 1])
+})
diff --git a/challenge-003/abigail/node/ch-2.js b/challenge-003/abigail/node/ch-2.js
index af1724bb18..a161017ede 100644
--- a/challenge-003/abigail/node/ch-2.js
+++ b/challenge-003/abigail/node/ch-2.js
@@ -1,7 +1,7 @@
#!/usr/local/bin/node
//
-// See ../README.md
+// See https://theweeklychallenge.org/blog/perl-weekly-challenge-003
//
//