Created
September 16, 2015 14:21
-
-
Save zigen/05878eeb9ad2a97b556f to your computer and use it in GitHub Desktop.
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
#!/Users/hrl7/.rbenv/shims/ruby | |
def solve | |
puts "Solver Start" | |
board = [ | |
[1, 0, 0, 0, 0, 0, 0, 0], | |
[1, 0, 0, 0, 0, 0, 0, 0], | |
[1, 0, 0, 0, 0, 0, 0, 0], | |
[1, 0, 0, 0, 0, 0, 0, 0], | |
[1, 0, 0, 0, 0, 0, 0, 0], | |
[1, 0, 0, 0, 0, 0, 0, 0], | |
[1, 0, 0, 0, 0, 0, 0, 0], | |
[1, 0, 0, 0, 0, 0, 0, 0], | |
] | |
show_board board | |
10.times do | |
increment board | |
end | |
show_board board | |
#search board | |
end | |
def increment board | |
increment_line board, 0 | |
end | |
def check_pos board,x,y | |
end | |
def increment_line board, line | |
(line..6).each do |y| | |
(0..7).each do |i| | |
if board[y][i] == 1 | |
board[y][i] = 0 | |
#print i, board[y][i] , "\n" | |
if i == 7 | |
board[y][0] = 1 | |
board = increment_line board, y + 1 | |
else | |
board[y][i+1] = 1 | |
end | |
return board | |
end | |
end | |
end | |
end | |
def search board | |
puts "=================" | |
puts "Seach" | |
stepped = true | |
while stepped | |
stepped = false | |
board.each_index do |y_index| | |
board_x = board[y_index] | |
board_x.each_index do |i| | |
if board_x[i] == 1 | |
#puts i.to_s + " : " + board_x[i].to_s | |
(y_index+1..8-1).each do |y| | |
#puts board[y][i] | |
if board[y][i] == 1 | |
stepped = true | |
board[y_index][i] = 0 | |
if i == 7 | |
board[y_index][0] = 1 | |
else | |
board[y_index][i+1] = 1 | |
end | |
show_board board | |
break | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
def show_board board | |
puts "=================" | |
for x_array in board | |
for pos in x_array | |
print pos.to_s + " " | |
end | |
print "\n" | |
end | |
end | |
solve | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment