Skip to content

Instantly share code, notes, and snippets.

@alexgolec
Created October 7, 2018 03:57
Show Gist options
  • Save alexgolec/e124e7a53243fc56e502b397567f49eb to your computer and use it in GitHub Desktop.
Save alexgolec/e124e7a53243fc56e502b397567f49eb to your computer and use it in GitHub Desktop.
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