Last active
January 5, 2017 17:27
-
-
Save Muzietto/a8f9c1d5807eb1d0555a33a896024fe2 to your computer and use it in GitHub Desktop.
Dynamic programming - Playing all possible solitaires on a board, throwing one die, up to the last square.
This file contains hidden or 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 numberSolitaire(arra) { | |
var dp = new Array(arra.length).fill(0); | |
dp[0] = arra[0]; | |
for (var i = 1; i < arra.length; i++) { | |
var max = -Infinity; | |
for (var j = 1; j <= 6; j++) { | |
if (i - j < 0) break; | |
max = Math.max(max, dp[i-j] + arra[i]); | |
} | |
dp[i] = max; | |
} | |
return dp[arra.length-1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://codility.com/programmers/lessons/17-dynamic_programming/number_solitaire/