diff options
| -rwxr-xr-x | challenge-122/stuart-little/node/ch-1.js | 8 | ||||
| -rwxr-xr-x | challenge-122/stuart-little/node/ch-2.js | 23 |
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) +} |
