Created
October 2, 2013 04:01
-
-
Save loganhasson/6788985 to your computer and use it in GitHub Desktop.
Working Tower of Hanoi that I don't entirely understand, but was able to piece together based on reading.
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
a = [1,2,3,4] | |
b = [] | |
c = [] | |
def move_disc(num_discs, from_peg, via_peg, to_peg) | |
watch_hannoi(from_peg, via_peg, to_peg) | |
sleep(1) | |
if num_discs == 1 | |
to_peg.unshift(from_peg.shift) | |
else | |
via_peg.unshift(from_peg.shift) | |
move_disc(num_discs-1, from_peg, via_peg, to_peg) | |
to_peg.unshift(via_peg.shift) | |
end | |
watch_hannoi(from_peg, via_peg, to_peg) | |
sleep(1) | |
to_peg | |
end | |
def watch_hannoi(from_peg, via_peg, to_peg) | |
system('clear') | |
puts from_peg.inspect | |
puts via_peg.inspect | |
puts to_peg.inspect | |
end | |
move_disc(4,a,b,c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment