feat(sterni/aoc/2022): day11 BQN solution

Change-Id: If9c510e3530ecc1acafa1d708eacf64eb1132db7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7583
Reviewed-by: sterni <sternenseemann@systemli.org>
Autosubmit: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
This commit is contained in:
sterni 2022-12-13 00:43:08 +01:00 committed by clbot
parent fc31f93eb5
commit 867210f084
2 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,41 @@
# needs export BQNLIBS=/path/to/mlochbaum/bqn-libs
Split •Import "/strings.bqn"˜¯11•SH "printenv""BQNLIBS"
ReadDec •Import "../../lib.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

View file

@ -15,6 +15,13 @@ depot.nix.readTree.drvTargets {
ngn-k
depot.tvix.eval
];
BQNLIBS = pkgs.fetchFromGitHub {
owner = "mlochbaum";
repo = "bqn-libs";
rev = "d56d8ea0b8c294fac7274678d9ab112553a03f42";
sha256 = "1c1bkqj62v8m13jgaa32ridy0fk5iqysq5b2qwxbqxhky5zwnk9h";
};
};
bqn = pkgs.runCommand "bqn-aoc-2022"