Skip to content

Instantly share code, notes, and snippets.

@dekajp
Last active December 15, 2015 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dekajp/5227749 to your computer and use it in GitHub Desktop.
Save dekajp/5227749 to your computer and use it in GitHub Desktop.
Project Euler 15 Starting in the top left corner of a 22 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.
http://projecteuler.net/problem=15
var memory;
var f = function(x,y){
var a=0,b=0;
console.log ( 'x:'+x+ ' y:'+y );
if (memory[x][y] !=0){
return memory[x][y];
}
if(x===0 && y===0) {
return 0;
}
if (x===0 || y===0 ) {
return memory[x][y]=1;
}
memory[x][y]= f(x-1,y)+f(x,y-1);
return memory[x][y];
}
var start=function(){
memory=new Array(21);
for(i=0;i<21;i++){
memory[i]=new Array(21);
for(j=0;j<21;j++){
memory[i][j]=0;
}
}
var result=0;
result=f(20,20);
console.log(result);
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment