Skip to content

Instantly share code, notes, and snippets.

@eduzol
Last active February 20, 2018 11:20
Show Gist options
  • Save eduzol/3f5a3800d1bffd50b2fadb97b46c8734 to your computer and use it in GitHub Desktop.
Save eduzol/3f5a3800d1bffd50b2fadb97b46c8734 to your computer and use it in GitHub Desktop.
Javascript method populationGrowth(simulationLength) that determines how many amoebas will exist after simulationLength steps
let fibonacci = ( n , dict ) =>{
if ( dict[n] ){
return dict[n];
}
if ( n <= 1 ){
return 1;
}
let fibN = fibonacci(n-1 , dict) + fibonacci(n-2 , dict);
return fibN;
}
let populationGrowth = ( simulationLength ) => {
if ( simulationLength < 0 ){
return -1;
}
let dict = {};
length = fibonacci(simulationLength , dict );
return length;
};
for ( n = 0 ; n < 10 ; n++ ){
console.log(populationGrowth(n));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment