Skip to content

Instantly share code, notes, and snippets.

@googya
Created April 16, 2014 12:51
Show Gist options
  • Save googya/10869444 to your computer and use it in GitHub Desktop.
Save googya/10869444 to your computer and use it in GitHub Desktop.
汉内塔
def move(a, b, c, n)
if n == 1
puts "move #{n} from #{a} to #{c}"
else
move(a, c, b, n - 1)
puts "move #{n} from #{a} to #{c}"
move(b, a, c, n - 1)
end
end
puts move "A", "B", "C", 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment