diff options
Diffstat (limited to 'challenge-112/stuart-little/node/ch-2.js')
| -rwxr-xr-x | challenge-112/stuart-little/node/ch-2.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-112/stuart-little/node/ch-2.js b/challenge-112/stuart-little/node/ch-2.js new file mode 100755 index 0000000000..d29b016779 --- /dev/null +++ b/challenge-112/stuart-little/node/ch-2.js @@ -0,0 +1,20 @@ +#!/usr/bin/env node + +// run <script> <number> + +let memo = [ + [[1,],], + [[1,1],[2,]], +]; + +function memoSteps(n) { + if (typeof(memo[n]) === 'undefined') { + memo[n] = [...(memoSteps(n-1).map(x => [1,...x])) , ...(memoSteps(n-2).map(x => [2,...x]))]; + } + return memo[n] +} + +const res = memoSteps(parseInt(process.argv[2])-1); +console.log(`${res.length} +${"-".repeat(12)}`); +res.forEach(x => console.log(x)); |
