diff options
| -rwxr-xr-x | challenge-112/stuart-little/node/ch-1.js | 7 | ||||
| -rwxr-xr-x | challenge-112/stuart-little/node/ch-2.js | 20 |
2 files changed, 27 insertions, 0 deletions
diff --git a/challenge-112/stuart-little/node/ch-1.js b/challenge-112/stuart-little/node/ch-1.js new file mode 100755 index 0000000000..2feea0c4b4 --- /dev/null +++ b/challenge-112/stuart-little/node/ch-1.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node + +// run <script> <path> + +const path = require('path'); + +console.log(path.resolve(process.argv[2])) 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)); |
