tvl-depot/users/sterni/exercises/aoc/2022/11/11.bqn
sterni 8fda0544d7 feat(sterni/aoc/2022): day13 BQN solution
Change-Id: I401ba09198d447628fa76d811fd4fe780baa8240
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7586
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Autosubmit: sterni <sternenseemann@systemli.org>
2022-12-13 14:52:19 +00:00

41 lines
1.2 KiB
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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