Skip to content

Instantly share code, notes, and snippets.

@taterbase
Created November 16, 2012 04:24
Show Gist options
  • Save taterbase/4084044 to your computer and use it in GitHub Desktop.
Save taterbase/4084044 to your computer and use it in GitHub Desktop.
Rice and chess
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