Created
October 7, 2018 03:57
-
-
Save alexgolec/e124e7a53243fc56e502b397567f49eb 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 count_sequences(start_position, num_hops): | |
cache = {} | |
def helper(position, num_hops): | |
if (position, num_hops) in cache: | |
return cache[ (position, num_hops) ] | |
if num_hops == 0: | |
return 1 | |
else: | |
num_sequences = 0 | |
for neighbor in neighbors(position): | |
num_sequences += helper(neighbor, num_hops - 1) | |
cache[ (position, num_hops) ] = num_sequences | |
return num_sequences | |
res = helper(start_position, num_hops) | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment