-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday04.2.py
78 lines (59 loc) · 1.79 KB
/
day04.2.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
file = "AOC_day4_input_bsp.txt"
document1 = []
document2 = []
total_worth = 0
def einlesen(filename):
"""
liest alle Zeilen eines Textfiles ein und speichert jede einzelne Zeile in einer Liste
"""
with open(filename, "r") as file:
# read file line by line and output the lines
numbers = []
for line in file:
line = line.strip()
line = line.replace(" ", " ")
line = line.split(": ")
numbers = line[1].split(" | ")
numbers[0] = numbers[0].split(" ")
numbers[1] = numbers[1].split(" ")
document1.append(numbers[0])
document2.append(numbers[1])
return document1, document2
def listenvergleich(liste1, liste2):
matches = 0
w = 0
a = 0
for element in liste1:
if element in liste2:
w = w + 1
a = a + 1
matches = w
return matches
einlesen(file)
a = 0
for element in document1:
print(a, ": ", element)
a = a + 1
print(" ")
# liste mit 1-ern erzeugen inselber länge wie doc1
no_of_cards = []
for item in document1:
no_of_cards.append(1)
print("Anzahl Karten: ", no_of_cards.count(1))
print(" ")
i = 0
for i in range(len(document1)): # i ist die Zeile
print(document1[i])
print(document2[i])
matching = listenvergleich(document1[i], document2[i])
print("Übereinstimmende Nos: ", matching)
j = 0
for j in range(i+1, matching+i+1):
no_of_cards[j] = no_of_cards[j] + no_of_cards[i] # das hier hat lange gedauert
print(" ")
total_worth = total_worth + listenvergleich(document1[i], document2[i])
a = 0
for element in no_of_cards:
print(a, ": ", element)
a = a+1
print("Gesamtzahl Karten: ", sum(no_of_cards))