Created
October 19, 2013 12:09
-
-
Save Scorpil/7055199 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
from copy import copy | |
def go(board, steps): | |
print "Step %d:" % (steps+1), board | |
new_board = copy(board) | |
for i, cell in enumerate(board): | |
if cell == 'S' and 'E' in board[i+1: i+6+1]: | |
return steps + 1 | |
if cell == 'R' and 'E' in board[i+1: i+6+1]: | |
new_board[i] = 'E' | |
elif isinstance(cell, int) and board[i+cell] == 'E': | |
new_board[i] = 'E' | |
if new_board == board: | |
return None # no solution | |
return go(new_board, steps+1) | |
board = ['S', 1, 'R', 4, 3, 4, 3, - 5, 2, -4, 'E'] | |
print go(board, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment