-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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