Skip to content

Instantly share code, notes, and snippets.

@andyfangdz
Created September 19, 2016 00:00
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 andyfangdz/4597c00a4e43438dbd7c37aa01ecc3e2 to your computer and use it in GitHub Desktop.
Save andyfangdz/4597c00a4e43438dbd7c37aa01ecc3e2 to your computer and use it in GitHub Desktop.
def DFS(depth=0, state=None):
if check_state_is_valid(depth, state):
report_found(state)
if depth >= target_depth:
return
for next_step in possible_steps(depth, state):
current_state = state
apply_step_on_state(next_step, state)
if is_valid_state(state):
DFS(depth + 1, state)
state = current_state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment