Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

トリボナッチ数列練習問題 #2486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
'use strict';
const memo = new Map();
memo.set(0, 0);
memo.set(1, 1);
function trib(n) {
if (memo.has(n)) {
return memo.get(n);

const culcuMap = new Map() ;

culcuMap.set(0, 0) ;

culcuMap.set(1, 0) ;

culcuMap.set(2, 1) ;

function sumMap(n){
if( culcuMap.has(n) ){
return culcuMap.get(n) ;
}
const value = trib(n - 1) + trib(n - 2);
memo.set(n, value);
return value;
}
const length = 40;
for (let i = 0; i <= length; i++) {
console.log(trib(i));
}
const value = sumMap(n-1) + sumMap(n-2) + sumMap(n-3) ;
culcuMap.set(n , value) ;
return culcuMap.get(n) ;
};

const length = 40
for(let i = 0; i <= length ; i++ ){
console.log( sumMap(i) );
};