aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-04-15 18:56:01 +0200
committerAbigail <abigail@abigail.be>2021-04-15 18:56:01 +0200
commitf4f74541386e7d473017e82ee919677fa61d667f (patch)
treeb46c4d5331314b57a9064dd28dd773f23617aaed
parentb1620c481366a458f47ca2eaac91715da0914f9d (diff)
downloadperlweeklychallenge-club-f4f74541386e7d473017e82ee919677fa61d667f.tar.gz
perlweeklychallenge-club-f4f74541386e7d473017e82ee919677fa61d667f.tar.bz2
perlweeklychallenge-club-f4f74541386e7d473017e82ee919677fa61d667f.zip
Node.js solution for week 108, part 2
-rw-r--r--challenge-108/abigail/README.md1
-rw-r--r--challenge-108/abigail/node/ch-2.js42
-rw-r--r--challenge-108/abigail/t/ctest.ini6
3 files changed, 46 insertions, 3 deletions
diff --git a/challenge-108/abigail/README.md b/challenge-108/abigail/README.md
index d97ab66dec..1f2b01eaf8 100644
--- a/challenge-108/abigail/README.md
+++ b/challenge-108/abigail/README.md
@@ -46,6 +46,7 @@ more informations.
* [Java](java/ch-2.java)
* [Lua](lua/ch-2.lua)
* [m4](m4/ch-2.m4)
+* [Node.js](node/ch-2.js)
* [Ocaml](ocaml/ch-2.ml)
* [Pascal](pascal/ch-2.p)
* [Perl](perl/ch-2.pl)
diff --git a/challenge-108/abigail/node/ch-2.js b/challenge-108/abigail/node/ch-2.js
new file mode 100644
index 0000000000..7911a70038
--- /dev/null
+++ b/challenge-108/abigail/node/ch-2.js
@@ -0,0 +1,42 @@
+#!/usr/local/bin/node
+
+//
+// See ../README.md
+//
+
+//
+// Run as: node ch-2.js
+//
+
+let COUNT = 10
+let PLAIN = 0
+let COMPUTE = 1
+
+let type = PLAIN
+
+if (process . argv . length > 2 &&
+ process . argv [2] == "compute") {
+ type = COMPUTE
+}
+
+if (type == PLAIN) {
+ console . log ("1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147")
+}
+
+if (type == COMPUTE) {
+ let bell = [[ 1 ]]
+ let x
+ for (x = 1; x < COUNT - 1; x ++) {
+ bell [x] = [bell [x - 1] [x - 1]]
+ let y
+ for (y = 1; y <= x; y ++) {
+ bell [x] [y] = bell [x] [y - 1] + bell [x - 1] [y - 1]
+ }
+ }
+
+ process . stdout . write ("1")
+ for (x = 0; x < COUNT - 1; x ++) {
+ process . stdout . write (", " + bell [x] [x] . toString ())
+ }
+ process . stdout . write ("\n")
+}
diff --git a/challenge-108/abigail/t/ctest.ini b/challenge-108/abigail/t/ctest.ini
index ab10b98257..b0643c4194 100644
--- a/challenge-108/abigail/t/ctest.ini
+++ b/challenge-108/abigail/t/ctest.ini
@@ -19,13 +19,13 @@ no_input = 1
[2-1/sed]
no_input = 0
-[2-1/awk,bash,c,lua,perl]
+[2-1/awk,bash,c,lua,node,perl]
skip = "Not for this language"
[2-2,2-3,2-4]
skip = "Only for Perl"
-[2-2/awk,bash,c,lua,perl]
+[2-2/awk,bash,c,lua,node,perl]
skip = 0
args = plain
@@ -33,6 +33,6 @@ args = plain
skip = 0
args = fetch
-[2-4/awk,bash,c,lua,perl]
+[2-4/awk,bash,c,lua,node,perl]
skip = 0
args = compute