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()
|
Loading…
Reference in New Issue
Block a user