aboutsummaryrefslogtreecommitdiff
path: root/challenge-104/abigail/node
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-03-18 20:12:35 +0100
committerAbigail <abigail@abigail.be>2021-03-18 20:12:35 +0100
commit3b126f6e1e8ebd10ac4201a45076ef58e0d368c4 (patch)
tree793c3ba9a76f9cbde8d08536b6683cd2abbc66a7 /challenge-104/abigail/node
parent8e4529e42ce886908d7efd93bd43d2fd9046ccf7 (diff)
downloadperlweeklychallenge-club-3b126f6e1e8ebd10ac4201a45076ef58e0d368c4.tar.gz
perlweeklychallenge-club-3b126f6e1e8ebd10ac4201a45076ef58e0d368c4.tar.bz2
perlweeklychallenge-club-3b126f6e1e8ebd10ac4201a45076ef58e0d368c4.zip
Alternative Node.js solution for week 104, part 1
Diffstat (limited to 'challenge-104/abigail/node')
-rw-r--r--challenge-104/abigail/node/ch-1a.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-104/abigail/node/ch-1a.js b/challenge-104/abigail/node/ch-1a.js
new file mode 100644
index 0000000000..9267ce8e8c
--- /dev/null
+++ b/challenge-104/abigail/node/ch-1a.js
@@ -0,0 +1,30 @@
+#!/usr/local/bin/node
+
+//
+// See ../README.md
+//
+
+//
+// Run as: node ch-1a.js
+//
+
+
+let cache = [0, 1]
+let max = 50
+
+function fusc (n) {
+ if (cache [n] === undefined) {
+ cache [n] = n % 2 == 1 ? fusc ((n - 1) / 2) + fusc ((n + 1) / 2)
+ : fusc (n / 2)
+ }
+ return cache [n]
+}
+
+for (i = 0; i < max; i ++) {
+ if (i > 0) {
+ process . stdout . write (" ")
+ }
+ process . stdout . write (fusc (i) . toString ())
+}
+
+process . stdout . write ("\n")