Day 14 (minified)
This commit is contained in:
@@ -9,16 +9,14 @@ first = next(lines)
|
||||
next(lines)
|
||||
|
||||
repl = (re.match(r"([A-Z]{2}) -> ([A-Z])", line).groups() for line in lines)
|
||||
repl = (v for (a, b), insert in repl for v in [(a + insert, a + b), (insert + b, a + b)])
|
||||
repl = (v for (a, b), m in repl for v in [(a+m, a+b), (m+b, a+b)])
|
||||
repl = {k: list(map(itemgetter(1), v)) for k, v in groupby(sorted(repl), itemgetter(0))}
|
||||
|
||||
combinations = Counter(first[a:a+2] for a in range(len(first)-1))
|
||||
combinations = Counter(first[i:i+2] for i in range(len(first)-1))
|
||||
for _ in range(40):
|
||||
combinations = {k: sum_val for k, v in repl.items() if (sum_val := sum(combinations.get(x, 0) for x in v)) > 0}
|
||||
|
||||
letters = ((l, cnt) for key, cnt in combinations.items() for l in key)
|
||||
letters = {k: sum(map(itemgetter(1), v)) for k, v in groupby(sorted(letters), itemgetter(0))}
|
||||
letters[first[0]] += 1
|
||||
letters = {k: sum(map(itemgetter(1), v)) for k, v in groupby(sorted(combinations.items()), lambda x: x[0][0])}
|
||||
letters[first[-1]] += 1
|
||||
|
||||
print((max(letters.values()) - min(letters.values())) // 2)
|
||||
print(max(letters.values()) - min(letters.values()))
|
||||
|
||||
Reference in New Issue
Block a user