2020 day 9
This commit is contained in:
parent
b307e09f2b
commit
ad53396ca6
33
2020/d9.py
Normal file
33
2020/d9.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
from lib import get_data
|
||||||
|
|
||||||
|
|
||||||
|
def part_1(data):
|
||||||
|
target = 0
|
||||||
|
xs = list(map(int, data.splitlines()))
|
||||||
|
for i in range(25, len(xs)):
|
||||||
|
x = xs[i]
|
||||||
|
good = False
|
||||||
|
for j in range(i - 25, i):
|
||||||
|
for k in range(j, i):
|
||||||
|
if xs[j] + xs[k] == x:
|
||||||
|
good = True
|
||||||
|
if not good:
|
||||||
|
print(x)
|
||||||
|
target = x
|
||||||
|
break
|
||||||
|
|
||||||
|
for i in range(len(xs)):
|
||||||
|
for j in range(i + 1, len(xs)):
|
||||||
|
if sum(xs[i : j + 1]) == target:
|
||||||
|
r = xs[i : j + 1]
|
||||||
|
print(min(r) + max(r))
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
data = get_data(__file__)
|
||||||
|
part_1(data)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@ -143,7 +143,8 @@ Solutions and utility script for Advent of Code challenges in Python.
|
|||||||
- Day 6: 4:11 (75th, finally on the leaderboard)
|
- Day 6: 4:11 (75th, finally on the leaderboard)
|
||||||
- Day 7: 24:39 (bad)
|
- Day 7: 24:39 (bad)
|
||||||
- Day 8: 6:26 (43th, tied George Hotz :)
|
- Day 8: 6:26 (43th, tied George Hotz :)
|
||||||
- Day 9:
|
- Day 9: 7:37 (choked bad)
|
||||||
|
- Day 10:
|
||||||
|
|
||||||
|
|
||||||
## AoC 2022
|
## AoC 2022
|
||||||
|
Loading…
Reference in New Issue
Block a user