Created
December 9, 2020 05:10
-
-
Save bluepichu/9ba663904749ab6658fd3ae7b688b01d 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
from typing import Dict, List, Set, Tuple | |
from advent import Input | |
import re | |
from collections import defaultdict | |
input = ( | |
Input(day = 9) | |
# .all() | |
.ints() | |
# .lines() | |
# .line_tokens() | |
# .line_tokens(sep = "\n", line_sep = "\n\n") | |
# .program() | |
) | |
magic = 0 | |
for i in range(25, len(input)): | |
ok =False | |
for j in range(i - 25, i): | |
for k in range(i - 25, i): | |
if input[j] != input[k] and input[j] + input[k] == input[i]: | |
ok = True | |
break | |
if ok: break | |
if not ok: | |
magic = input[i] | |
break | |
print("pt1:", magic) | |
for i in range(len(input)): | |
for j in range(i+1, len(input)): | |
if sum(input[i:j]) == magic: | |
print("pt2:", min(input[i:j]) + max(input[i:j])) |
To fix part 2 printing two answers, couldn't you just start j
at i+2
? That way, all slices would start with at least two numbers in them.
It's advent, and as long as you get the right answer, it doesn't really matter how you got there, but 🤷
Yeah, that would absolutely work; I just didn't think of it at the time 🙂
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Part 2 prints two answers. The second one is just
2*magic
and comes from just selecting the range[i, i+1)
ifi
is the index with the magic number and can be ignored.