Created
October 7, 2018 03:30
-
-
Save alexgolec/1fde342bb2855c76da0ea74d083af672 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
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