Created
November 16, 2012 04:24
-
-
Save taterbase/4084044 to your computer and use it in GitHub Desktop.
Rice and chess
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
function rice_chessboard ( A ) { | |
return checkPath(A[0][0], 0, 0, A) | |
} | |
function checkPath(val, x, y, board){ | |
if(board[x + 1] && board[x][y+1]){ //If there is room | |
var possibility1 = checkPath(val + board[x][y+1], x, (y+1), board); | |
var possibility2 = checkPath(val + board[x+1][y], (x+1), y, board); | |
return possibility1 > possibility2 ? possibility1 : possibility2; | |
} else if (board[x + 1]){ | |
return checkPath(val + board[x+1][y], (x+1), y, board); | |
} else if (board[x][y+1]){ | |
return checkPath(val + board[x][y+1], x, (y+1), board); | |
} else { | |
return val; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment