Skip to content

Instantly share code, notes, and snippets.

@alexgolec
Created October 7, 2018 03:30
Show Gist options
  • Save alexgolec/1fde342bb2855c76da0ea74d083af672 to your computer and use it in GitHub Desktop.
Save alexgolec/1fde342bb2855c76da0ea74d083af672 to your computer and use it in GitHub Desktop.
def yield_sequences(starting_position, num_hops, sequence=None):
if sequence is None:
sequence = [starting_position]
if num_hops == 0:
yield sequence
return
for neighbor in neighbors(starting_position):
yield from yield_sequences(
neighbor, num_hops - 1, sequence + [neighbor])
def count_sequences(starting_position, num_hops):
num_sequences = 0
for sequence in yield_sequences(starting_position, num_hops):
num_sequences += 1
return num_sequences
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment