Skip to content

Instantly share code, notes, and snippets.

@Scorpil
Created October 19, 2013 12:09
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 Scorpil/7055199 to your computer and use it in GitHub Desktop.
Save Scorpil/7055199 to your computer and use it in GitHub Desktop.
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