Skip to content

Instantly share code, notes, and snippets.

@micedreams
Created November 12, 2023 11:21
Show Gist options
  • Save micedreams/a1c4338161c88f87d6a7422fb4ad34c9 to your computer and use it in GitHub Desktop.
Save micedreams/a1c4338161c88f87d6a7422fb4ad34c9 to your computer and use it in GitHub Desktop.
hanoi
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