-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday6.py
61 lines (48 loc) · 1.45 KB
/
day6.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
def clean_line(line):
line = line.strip()
line = line.replace("\n","")
return line
def run_2(data_input):
total = 0
with open(data_input, "r") as reader:
questions = ""
newline = True
while True:
line = reader.readline()
if line == "\n":
total += len(set(questions))
questions = ""
newline = True
elif line == "":
total += len(set(questions))
break
else:
line = clean_line(line)
if not newline:
for c in questions:
if c not in line:
questions = questions.replace(c,"")
else:
questions = line
newline = False
print(f"Total = {total}")
def run(data_input):
total = 0
with open(data_input, "r") as reader:
questions = []
while True:
line = reader.readline()
if line == "\n":
total += len(set(questions))
questions = []
elif line == "":
total += len(set(questions))
break
else:
line = clean_line(line)
chars = [c for c in line]
questions += chars
print(f"Total = {total}")
if __name__ == "__main__":
data_input = "data/day6.txt"
run_2(data_input)