Skip to content

Instantly share code, notes, and snippets.

@Soryu
Created February 11, 2012 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Soryu/1804813 to your computer and use it in GitHub Desktop.
Save Soryu/1804813 to your computer and use it in GitHub Desktop.
Ruby program to solve clock anomaly in Final Fantasy XIII-2
# 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