-
Notifications
You must be signed in to change notification settings - Fork 1
/
09.py
33 lines (24 loc) · 862 Bytes
/
09.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import fileinput
numbers = [int(line.replace('\n', '')) for line in fileinput.input()]
def is_valid_idx(idx):
for x in range(idx-25, idx):
for y in range(x+1, idx):
if numbers[x] + numbers[y] == numbers[idx]:
return True
return False
def part1():
for idx in range(25, len(numbers)):
if not is_valid_idx(idx):
return numbers[idx]
def part2(part1_result):
for x in range(25, len(numbers)):
for y in range(x+1, len(numbers)):
section = list(map(lambda z: numbers[z], range(x, y+1)))
section_sum = sum(section)
if section_sum > part1_result:
break
if section_sum == part1_result:
return min(section) + max(section)
part1 = part1()
print(part1)
print(part2(part1))