This repository has been archived on 2018-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
aoc2018/2/checksum.py~

31 lines
581 B
Python
Executable File

#!/usr/bin/env python3
def checksum(l):
double = 0
triple = 0
for item in l:
d, t = count_duplicate(item)
double += d
triple += t
return double * triple
def count_duplicate(item):
double = 0
triple = 0
c = dict()
for i in item:
if i in c:
c[i] += 1
else:
c[i] = 1
for k,v in c.items():
if v == 2:
double =11
if v == 3:
triple = 1
return (double, triple)
if __name__ == '__main__':
l = sys.stdin.readlines()
print(checksum(l))