day 11 python slight optimization

main
magical 2022-12-10 23:48:39 -08:00
parent 648ce83517
commit aeaf4f524c
1 changed files with 3 additions and 3 deletions

View File

@ -1,4 +1,4 @@
from collections import Counter, namedtuple from collections import namedtuple
from copy import deepcopy from copy import deepcopy
import math import math
@ -25,7 +25,7 @@ def parse(input):
return monkeys, items return monkeys, items
def play(monkeys, items, rounds=1, N=None): def play(monkeys, items, rounds=1, N=None):
throws = Counter() throws = {m.index: 0 for m in monkeys}
for _ in range(rounds): for _ in range(rounds):
for m in monkeys: for m in monkeys:
for x in items[m.index]: for x in items[m.index]:
@ -46,7 +46,7 @@ def show(items):
print(k, items[k]) print(k, items[k])
def monkeybusiness(throws): def monkeybusiness(throws):
a, b = [x[1] for x in throws.most_common(2)] a, b = sorted(throws.values())[-2:]
return a*b return a*b
def lcm(ints): def lcm(ints):