Skip to content

Instantly share code, notes, and snippets.

@stefanv
Last active December 10, 2020 17:05
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 stefanv/bd098428fe2194bc0201ab60abbdb20a to your computer and use it in GitHub Desktop.
Save stefanv/bd098428fe2194bc0201ab60abbdb20a to your computer and use it in GitHub Desktop.
Advent of Code :: Problem 10
adapters = np.sort(adapters)
start = 0
end = np.max(adapters) + 3
cache = {}
def next_in_line(last_link):
if last_link in cache:
return cache[last_link]
if end - last_link <= 3:
cache[last_link] = 1
return 1
# Which adapters can I use next?
D = adapters - last_link
candidates = adapters[np.where((0 < D) & (D <= 3))[0]]
S = 0
for c in candidates:
S = S + next_in_line(c)
cache[last_link] = S
return S
print(next_in_line(start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment