Created
February 11, 2012 22:39
-
-
Save Soryu/1804813 to your computer and use it in GitHub Desktop.
Ruby program to solve clock anomaly in Final Fantasy XIII-2
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
# Ruby program to solve clock anomaly in Final Fantasy XIII-2 | |
clock = [4,5,5,5,5,3,4,4,5,4,5,3] | |
def solve(clock, index, steps) | |
if clock.reduce(:+) == 0 | |
print "Solution found!\n" | |
p steps | |
exit | |
end | |
if clock[index] == 0 | |
return false | |
end | |
steps << index | |
element = clock[index] | |
clock2 = clock.dup | |
clock2[index] = 0 | |
solve(clock2, (index + element) % clock.count, steps.dup) | |
solve(clock2, (index - element) % clock.count, steps.dup) | |
end | |
Range.new(0, clock.count - 1).each do |index| | |
solve(clock, index, []) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment