Created
November 12, 2023 11:21
-
-
Save micedreams/a1c4338161c88f87d6a7422fb4ad34c9 to your computer and use it in GitHub Desktop.
hanoi
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
def tower(count,from,to,via) | |
if count == 1 | |
to.unshift(from.shift) | |
puts"\n Move disk 1 from A to C\n" | |
else | |
tower(count - 1, from, via, to) | |
to.unshift(from.shift) | |
puts"\n Move disk #{count} from C to A\n" | |
tower(count - 1, via, to, from) | |
end | |
end | |
puts"\n<<<<<<<<<<<<<<TOWER OF HANOI>>>>>>>>>>>>>>>\n" | |
puts"Enter the number of disks" | |
count=gets | |
count=count.to_i | |
a = *(1..count) | |
b = [] | |
c = [] | |
tower(count, a, c, b) | |
puts a,b,c | |
puts"\n End of Program :)\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment