Skip to content

Instantly share code, notes, and snippets.

@dekajp dekajp/ProjectEuler_Problem15.js Secret
Last active Dec 15, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.