-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecksum.py
36 lines (31 loc) · 833 Bytes
/
checksum.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
from collections import defaultdict
def part1():
barcodes = []
check_input = defaultdict(int)
with open('codes.txt') as f:
barcodes = f.readlines()
for b in barcodes:
for c in [chr(x) for x in range(97,97+26)]:
if b.count(c) == 2:
check_input[2] += 1
break
for c in [chr(x) for x in range(97,97+26)]:
if b.count(c) == 3:
check_input[3] += 1
break
print check_input[2] * check_input[3]
#part1()
def part2():
barcodes = []
with open('codes.txt') as f:
barcodes = f.readlines()
for i in barcodes:
for j in barcodes:
if i == j:
continue
for n in range(len(i)):
i_cmp = i[0:n] + '.' + i[n+1:]
j_cmp = j[0:n] + '.' + j[n+1:]
if i_cmp == j_cmp:
print i_cmp
part2()