-
Notifications
You must be signed in to change notification settings - Fork 0
/
01.py
executable file
·43 lines (35 loc) · 958 Bytes
/
01.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
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
# Eingabe lesen
with open("input/01.txt") as infile:
input = infile.read().split("\n")
# Teil 1
found = False
solution = False
i = 0
for num in input:
i += 1
for num2 in input[i:]:
if int(num) + int(num2) == 2020:
solution = int(num) * int(num2)
print(f"Gefunden: {num} + {num2} = 2020, {num} * {num2} = {solution}")
break
if solution != False:
break
# Teil 2
found = False
solution = False
i1 = 0
i2 = 0
for num in input:
i1 += 1
for num2 in input[i1:]:
i2 = i1 + 1
for num3 in input[i2:]:
if int(num) + int(num2) + int(num3) == 2020:
solution = int(num) * int(num2) * int(num3)
print(f"Gefunden: {num} + {num2} + {num3} = 2020, {num} * {num2} * {num3} = {solution}")
break
if solution != False:
break
if solution != False:
break