day11 part2
This commit is contained in:
parent
7874d21e18
commit
695b77fef7
@ -1,4 +1,5 @@
|
||||
import shared
|
||||
import math
|
||||
from scanf import scanf
|
||||
import matrix
|
||||
from dataclasses import dataclass
|
||||
@ -18,7 +19,6 @@ class Monkey:
|
||||
inspect_count: int = 0
|
||||
|
||||
|
||||
|
||||
def load_monkeys(lines):
|
||||
monkeys = []
|
||||
count = 0
|
||||
@ -52,14 +52,13 @@ def load_monkeys(lines):
|
||||
)
|
||||
monkeys.append(monkey)
|
||||
count+=1
|
||||
return monkeys
|
||||
lcm = math.lcm(*[m.div for m in monkeys])
|
||||
return monkeys, lcm
|
||||
|
||||
def part1(lines):
|
||||
monkeys = load_monkeys(lines)
|
||||
for monkey in monkeys:
|
||||
print(monkey)
|
||||
monkeys, _ = load_monkeys(lines)
|
||||
|
||||
for current_round in range(20): # TODO: WHILE
|
||||
for current_round in range(20):
|
||||
for monkey in monkeys:
|
||||
for item in monkey.items:
|
||||
monkey.inspect_count += 1
|
||||
@ -68,9 +67,7 @@ def part1(lines):
|
||||
item = monkey.op(item, item)
|
||||
else:
|
||||
item = monkey.op(item, monkey.by)
|
||||
print(item,monkey.by, monkey.op)
|
||||
item = item // 3
|
||||
print(item)
|
||||
if item % monkey.div == 0:
|
||||
to = monkey.t
|
||||
else:
|
||||
@ -85,15 +82,12 @@ def part1(lines):
|
||||
print(total)
|
||||
|
||||
|
||||
|
||||
|
||||
def part2(lines):
|
||||
monkeys = load_monkeys(lines)
|
||||
monkeys, lcm = load_monkeys(lines)
|
||||
|
||||
for current_round in range(10000):
|
||||
for monkey in monkeys:
|
||||
print(monkey)
|
||||
|
||||
for current_round in range(10000): # TODO: WHILE
|
||||
for monkey in monkeys:
|
||||
for item in monkey.items:
|
||||
monkey.inspect_count += 1
|
||||
if monkey.by is None:
|
||||
@ -101,13 +95,13 @@ def part2(lines):
|
||||
item = monkey.op(item, item)
|
||||
else:
|
||||
item = monkey.op(item, monkey.by)
|
||||
item = item % lcm
|
||||
if item % monkey.div == 0:
|
||||
to = monkey.t
|
||||
else:
|
||||
to = monkey.f
|
||||
monkeys[to].items.append(item)
|
||||
monkey.items = []
|
||||
print("-----current round", current_round)
|
||||
|
||||
counts = list(sorted([monkey.inspect_count for monkey in monkeys]))
|
||||
print(counts)
|
||||
|
Loading…
Reference in New Issue
Block a user