From aeaf4f524c380118a62fc5881451d17578d14e63 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Sat, 10 Dec 2022 23:48:39 -0800 Subject: [PATCH] day 11 python slight optimization --- day11/sol.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/day11/sol.py b/day11/sol.py index 52f348c..a866ee4 100644 --- a/day11/sol.py +++ b/day11/sol.py @@ -1,4 +1,4 @@ -from collections import Counter, namedtuple +from collections import namedtuple from copy import deepcopy import math @@ -25,7 +25,7 @@ def parse(input): return monkeys, items def play(monkeys, items, rounds=1, N=None): - throws = Counter() + throws = {m.index: 0 for m in monkeys} for _ in range(rounds): for m in monkeys: for x in items[m.index]: @@ -46,7 +46,7 @@ def show(items): print(k, items[k]) def monkeybusiness(throws): - a, b = [x[1] for x in throws.most_common(2)] + a, b = sorted(throws.values())[-2:] return a*b def lcm(ints):