tvl-depot/users/sterni/exercises/aoc/2022/11/11.bqn

42 lines
1.2 KiB
BQN
Raw Normal View History

# needs export BQNLIBS=/path/to/mlochbaum/bqn-libs
ReadDec,ImportBqnLibs •Import "../../lib.bqn"
Split ImportBqnLibs "strings.bqn"
MakeOp {
𝕊 a"+"b: 𝕊 a+b;
𝕊 a"*"b: 𝕊 a×b;
𝕊 aopb:
isxs (<"old") (¨) ab
{op´ (𝕩xs) ReadDec¨ is}
}
ParseMonkey {
·itemsopifthenelse:
{
initial ReadDec¨ ", " Split 18items
op MakeOp " " Split 19op
if ReadDec 21if
then ReadDec 29then
else ReadDec 30else
}
}
monkeys ParseMonkey¨ 1' '((+`()¨))0(¨/)•FLines "input"
items {𝕩.initial}¨ monkeys
lim ×´{𝕩.if}¨ monkeys
Sim {
div 𝕊 len:
Turn {
items 𝕊 turnidx:
i (monkeys)|turnidx
m imonkeys
worry lim|div÷˜ m.Op¨ iitems
elsethen 20 (=(m.if|)) worry
then, else(˜¨)(m.thenm.else) ˙(i) items
}
×´2+˝(<items) (()(>(()=|)¨)×(¨˘)>(»Turn`)) len×items
}
•Out "day11.1: "•Fmt 3 Sim 20
•Out "day11.2: "•Fmt 1 Sim 10000