diff --git a/app.js b/app.js deleted file mode 100644 index ad9a93a7..00000000 --- a/app.js +++ /dev/null @@ -1 +0,0 @@ -'use strict'; diff --git a/fib.js b/fib.js new file mode 100644 index 00000000..28707bff --- /dev/null +++ b/fib.js @@ -0,0 +1,19 @@ +'use strict'; +console.time('fib'); +const memo = new Map(); +memo.set(0, 0); +memo.set(1, 0); +memo.set(2, 1); +function fib(n){ + if(memo.has(n)){ + return memo.get(n); + } + const v = fib(n - 1) + fib(n - 2); + memo.set(n, v); + return v; +} +let l = process.argv[2] || 10; +for(let i = 0; i <= l; i++){ + console.log(fib(i)); +} +console.timeEnd('fib'); \ No newline at end of file diff --git a/trib.js b/trib.js new file mode 100644 index 00000000..67cf240f --- /dev/null +++ b/trib.js @@ -0,0 +1,19 @@ +'use strict'; +console.time('trib'); +const memo = new Map(); +memo.set(0, 0); +memo.set(1, 0); +memo.set(2, 1); +function trib(n){ + if(memo.has(n)){ + return memo.get(n); + } + const v = trib(n - 1) + trib(n - 2) + trib(n - 3); + memo.set(n, v); + return v; +} +let l = process.argv[2] || 10; +for(let i = 0; i <= l; i++){ + console.log(trib(i)); +} +console.timeEnd('trib'); \ No newline at end of file