Created
October 2, 2013 05:16
-
-
Save sarony/6789407 to your computer and use it in GitHub Desktop.
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 = [] | |
| all = [a, b, c] | |
| def aab_move(a, b, c) | |
| b.unshift(a.first) | |
| a.shift | |
| c.unshift(a.first) | |
| a.shift | |
| c.unshift(b.first) | |
| b.shift | |
| end | |
| def find_empty_array(a,b,c,all) | |
| empty_array=[] | |
| all.each{|peg| empty_array=peg if peg.empty?} | |
| return empty_array | |
| end | |
| def includes_3(a, b, c, all) | |
| array_3=[] | |
| all.each{|peg| array_3=peg if peg.include?(3)} | |
| return array_3 | |
| end | |
| def move_to_empty(a, b, c, all) | |
| empty_array = find_empty_array(a,b,c,all) | |
| array_3 = includes_3(a,b,c,all) | |
| empty_array.unshift(array_3.first) | |
| array_3.shift | |
| end | |
| def c_to_a(a,c) | |
| a.unshift(c.first) | |
| c.shift | |
| end | |
| def set_1(a, b, c, all) | |
| aab_move(a, b, c) | |
| move_to_empty(a,b,c, all) | |
| c_to_a(a,c) | |
| end | |
| puts "Tower in the beginning:" | |
| puts "This is A: #{a}" | |
| puts "This is B: #{b}" | |
| puts "This is C: #{c}" | |
| set_1(a,b,c,all) | |
| b.unshift(c.first) | |
| c.shift | |
| set_1(a,b,c,all) | |
| c.unshift(b.first) | |
| b.shift | |
| aab_move(a, b, c) | |
| puts "Tower in the end:" | |
| puts "This is A: #{a}" | |
| puts "This is B: #{b}" | |
| puts "This is C: #{c}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment