[py] Port 2021_14
This commit is contained in:
parent
1dc77551b3
commit
81945a973d
4 changed files with 12 additions and 17 deletions
|
|
@ -2,9 +2,11 @@ import sys
|
|||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
from .y2021 import d14
|
||||
from .y2022 import d01, d02, d03, d04
|
||||
|
||||
DAYS = {
|
||||
"2021_14": y2021.d14.solve,
|
||||
"2022_01": y2022.d01.solve,
|
||||
"2022_02": y2022.d02.solve,
|
||||
"2022_03": y2022.d03.solve,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import argparse
|
||||
from pathlib import Path
|
||||
from collections import Counter
|
||||
|
||||
|
||||
def step(pairs, rules):
|
||||
result = Counter()
|
||||
for pair, amount in pairs.items():
|
||||
|
|
@ -13,6 +13,7 @@ def step(pairs, rules):
|
|||
result[pair] += amount
|
||||
return result
|
||||
|
||||
|
||||
def count_chars(template, pairs):
|
||||
chars = Counter()
|
||||
for pair, amount in pairs.items():
|
||||
|
|
@ -20,17 +21,12 @@ def count_chars(template, pairs):
|
|||
chars[template[-1]] += 1
|
||||
return chars
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("file", type=Path)
|
||||
args = parser.parse_args()
|
||||
|
||||
with open(args.file) as f:
|
||||
template = next(f).strip()
|
||||
next(f)
|
||||
def solve(inputstr):
|
||||
template, rest = inputstr.split("\n\n", maxsplit=1)
|
||||
rules = {}
|
||||
for line in f:
|
||||
pair, char = line.strip().split(" -> ")
|
||||
for line in rest.splitlines():
|
||||
pair, char = line.split(" -> ")
|
||||
rules[pair] = (pair[0] + char, char + pair[1])
|
||||
|
||||
pairs = Counter(template[i : i + 2] for i in range(len(template) - 1))
|
||||
|
|
@ -46,6 +42,3 @@ def main():
|
|||
|
||||
chars = count_chars(template, pairs).most_common()
|
||||
print(f"Part 2: {chars[0][1] - chars[-1][1]}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue