aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-07-19 09:34:21 -0400
committerchirvasitua <stuart-little@users.noreply.github.com>2021-07-19 09:34:21 -0400
commit1c93949e2da1f7c790854bfbefcf6d6fd2e4b04d (patch)
treee0e13b5863e6d9bc619c7d98af92b96081c54e10
parent675c4ed9a3b441729b9558c051638027242ba77a (diff)
downloadperlweeklychallenge-club-1c93949e2da1f7c790854bfbefcf6d6fd2e4b04d.tar.gz
perlweeklychallenge-club-1c93949e2da1f7c790854bfbefcf6d6fd2e4b04d.tar.bz2
perlweeklychallenge-club-1c93949e2da1f7c790854bfbefcf6d6fd2e4b04d.zip
1st commit on 122_node
-rwxr-xr-xchallenge-122/stuart-little/node/ch-1.js8
-rwxr-xr-xchallenge-122/stuart-little/node/ch-2.js23
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-122/stuart-little/node/ch-1.js b/challenge-122/stuart-little/node/ch-1.js
new file mode 100755
index 0000000000..20b3e377e3
--- /dev/null
+++ b/challenge-122/stuart-little/node/ch-1.js
@@ -0,0 +1,8 @@
+#!/usr/bin/env node
+
+// run <script> <space-separated numbers>
+
+console.log(
+ process.argv.slice(2).map(x => parseFloat(x)).reduce(
+ (acc,val,ix) => acc.concat((acc[acc.length-1]*ix+val)/(ix+1)),[0,]).slice(1)
+)
diff --git a/challenge-122/stuart-little/node/ch-2.js b/challenge-122/stuart-little/node/ch-2.js
new file mode 100755
index 0000000000..a03dd1e3cd
--- /dev/null
+++ b/challenge-122/stuart-little/node/ch-2.js
@@ -0,0 +1,23 @@
+#!/usr/bin/env node
+
+// run <script> <score>
+
+function comp(nr,bd){
+ tab=[[[],],]
+ for (let n=1; n <= nr; n++){
+ item=[]
+ for (let i=1; i <= bd; i++){
+ if (tab.length >= i){
+ suppPrev = tab.slice(-i)[0].map( ar => [i].concat(ar) )
+ item = item.concat(suppPrev)
+ }
+ }
+ if (tab.length >= bd) { tab=tab.slice(1) }
+ tab.push(item)
+ }
+ return tab.slice(-1)[0]
+}
+
+for (cmp of comp(parseInt(process.argv[2]), 3)) {
+ console.log(cmp)
+}