Skip to content

Instantly share code, notes, and snippets.

@takuma-saito
Last active February 3, 2019 09:41
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 takuma-saito/af066bc4016907bd8da055f974ced0fc to your computer and use it in GitHub Desktop.
Save takuma-saito/af066bc4016907bd8da055f974ced0fc to your computer and use it in GitHub Desktop.
apuzzle-83.rb
def out(from, to, k)
$state[to - 1] += 1
$state[from - 1] -= 1
puts "[#{k}]: #{from} -> #{to}, #{$state}"
end
def move_2_to_3(k)
return if k == 0
move_2_to_1(k - 1)
out(2, 3, k)
move_1_to_2(k - 1)
move_2_to_3(k - 1)
end
def move_2_to_1(k)
return if k == 0
move_2_to_3(k - 1)
out(2, 1, k)
move_3_to_2(k - 1)
move_2_to_1(k - 1)
end
def move_1_to_2(k)
return if k == 0
move_1_to_2(k - 1)
move_2_to_3(k - 1)
out(1, 2, k)
move_3_to_2(k - 1)
end
def move_2_to_3(k)
return if k == 0
move_2_to_1(k - 1)
out(2, 3, k)
move_1_to_2(k - 1)
move_2_to_3(k - 1)
end
def move_3_to_2(k)
return if k == 0
move_3_to_2(k - 1)
move_2_to_1(k - 1)
out(3, 2, k)
move_1_to_2(k - 1)
end
def move_1_to_3(k)
return if k == 0
move_1_to_2(k - 1)
move_2_to_3(k - 1)
out(1, 2, k)
move_3_to_2(k - 1)
move_2_to_1(k - 1)
out(2, 3, k)
move_1_to_2(k - 1)
move_2_to_3(k - 1)
end
count = 4
$state = [count, 0, 0]
move_1_to_3(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment