Last active
December 10, 2020 17:05
-
-
Save stefanv/bd098428fe2194bc0201ab60abbdb20a to your computer and use it in GitHub Desktop.
Advent of Code :: Problem 10
This file contains hidden or 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
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