-
-
Save dustMason/487eabfa2cafd2e2b0c4814903c21772 to your computer and use it in GitHub Desktop.
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
def optimal_move state | |
return state if Math.sqrt(state) % 1 == 0 # its a perfect square | |
(1..Math.sqrt(state)).each { |n| return n*n if optimal_move(state - (n*n)) == -1 } | |
return -1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment