summaryrefslogtreecommitdiff
path: root/2016/4a.py
blob: e5dfe7f6b05ac7f6e279d4436b90afaaabfb47f0 (plain)
1
2
3
4
5
#!/usr/bin/env python3

import sys, re, functools

print(functools.reduce(lambda a,t:a+int(t[1]),filter(lambda t:"".join(x[1] for x in sorted([(len(p[0]),p[1]) for p in re.findall(r"((.)\2*)","".join(sorted(t[0].replace("-",""))))],key=lambda t:(-t[0],t[1]))[:5])==t[2],[re.match(r"([-a-z]+)-(\d+)\[([a-z]+)\]",r).groups() for r in sys.stdin.read().split("\n")[:-1]]),0))