-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday04.py
More file actions
33 lines (27 loc) · 811 Bytes
/
day04.py
File metadata and controls
33 lines (27 loc) · 811 Bytes
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
def calc_a(input):
count = 0
for row in input.split('\n'):
count += 1 if verify_row(row) else 0
return count
def verify_row(row):
tokens = row.split()
for i, t1 in enumerate(tokens):
# print(i, t1, tokens[:i] + tokens[i + 1:])
for t2 in (tokens[:i] + tokens[i + 1:]):
if t1 == t2:
return False
return True
# B
def calc_b(input):
count = 0
for row in input.split('\n'):
count += 1 if verify_row_b(row) else 0
return count
def verify_row_b(row):
tokens = row.split()
for i, t1 in enumerate(tokens):
# print(i, t1, tokens[:i] + tokens[i + 1:])
for t2 in (tokens[:i] + tokens[i + 1:]):
if ''.join(sorted(t1)) == ''.join(sorted(t2)):
return False
return True