day14: code shortening (*params are cool :)
This commit is contained in:
parent
55e62174db
commit
765f74e765
12
day14.py
12
day14.py
@ -20,7 +20,7 @@ def getInitialDicts(puzzle: List[str]) -> (Dict[str, int], Dict[str, int], Dict[
|
|||||||
return pairs, charcount, inserts
|
return pairs, charcount, inserts
|
||||||
|
|
||||||
|
|
||||||
def insert(pairs: Dict[str, int], charcount: Dict[str, int], inserts: Dict[str, str], count: int):
|
def insert(count: int, pairs: Dict[str, int], charcount: Dict[str, int], inserts: Dict[str, str]) -> int:
|
||||||
for _ in range(count):
|
for _ in range(count):
|
||||||
new_pairs = {}
|
new_pairs = {}
|
||||||
for p in pairs:
|
for p in pairs:
|
||||||
@ -31,17 +31,15 @@ def insert(pairs: Dict[str, int], charcount: Dict[str, int], inserts: Dict[str,
|
|||||||
new_pairs[p2] = new_pairs.get(p2, 0) + pairs[p]
|
new_pairs[p2] = new_pairs.get(p2, 0) + pairs[p]
|
||||||
pairs = new_pairs
|
pairs = new_pairs
|
||||||
|
|
||||||
|
return max(charcount.values()) - min(charcount.values())
|
||||||
|
|
||||||
|
|
||||||
class Day(AOCDay):
|
class Day(AOCDay):
|
||||||
test_solutions_p1 = [1588, 3230]
|
test_solutions_p1 = [1588, 3230]
|
||||||
test_solutions_p2 = [2188189693529, 3542388214529]
|
test_solutions_p2 = [2188189693529, 3542388214529]
|
||||||
|
|
||||||
def part1(self) -> Any:
|
def part1(self) -> Any:
|
||||||
pairs, charcount, inserts = getInitialDicts(self.getInput())
|
return insert(10, *getInitialDicts(self.getInput()))
|
||||||
insert(pairs, charcount, inserts, 10)
|
|
||||||
return max(charcount.values()) - min(charcount.values())
|
|
||||||
|
|
||||||
def part2(self) -> Any:
|
def part2(self) -> Any:
|
||||||
pairs, charcount, inserts = getInitialDicts(self.getInput())
|
return insert(40, *getInitialDicts(self.getInput()))
|
||||||
insert(pairs, charcount, inserts, 40)
|
|
||||||
return max(charcount.values()) - min(charcount.values())
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user