-
Notifications
You must be signed in to change notification settings - Fork 0
/
d6.py
52 lines (47 loc) · 1.05 KB
/
d6.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
input_file = open('inputs/d6.txt', 'r')
lines = input_file.read().splitlines()
import string
import time
t0 = time.time()
groups = []
str_tmp = ''
for i in range(len(lines)):
if lines[i] == '':
groups.append(str_tmp)
str_tmp = ''
continue
str_tmp += lines[i] + ' '
groups.append(str_tmp)
t1 = time.time()
print((t1-t0)*1000, ' ms')
# part1
t0 = time.time()
counts_total = 0
counts_per_group = 0
for group in groups:
for char in string.ascii_lowercase:
if group.count(char) > 0:
counts_per_group += 1
counts_total += counts_per_group
counts_per_group = 0
t1 = time.time()
print(counts_total)
print((t1-t0)*1000, ' ms')
# part2
t0 = time.time()
counts_total = 0
counts_per_group = 0
for group in groups:
asList = group[:-1].split(' ')
for char in string.ascii_lowercase:
isPresent = True
for vote in asList:
if vote.count(char) == 0:
isPresent = False
if isPresent:
counts_per_group+=1
counts_total+= counts_per_group
counts_per_group =0
t1 = time.time()
print(counts_total)
print((t1-t0)*1000, ' ms')