about summary refs log tree commit diff
path: root/users/sterni/exercises/aoc/2022
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2022-12-20T18·51+0100
committerclbot <clbot@tvl.fyi>2022-12-20T19·03+0000
commit68555896de3510c560587433acec3470e289c999 (patch)
tree09e553a87538856b0564930fcb662b6030e4d46e /users/sterni/exercises/aoc/2022
parentba719f8f5e8a1bb55a9f4fc99cd0e853f7ec62b8 (diff)
feat(sterni/aoc/2022): day20 BQN solution r/5431
This solution feels very un-BQN-esque, but I could not get it to work by
doing arithmetic operations on an array of indices for any input but the
example one. It's still decently fact considering that we create so many
intermediate arrays at each step.

Change-Id: I883409b4d99d4954312df9b9a9ffc568c39f7726
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7602
Reviewed-by: sterni <sternenseemann@systemli.org>
Autosubmit: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/sterni/exercises/aoc/2022')
-rw-r--r--users/sterni/exercises/aoc/2022/20/20.bqn13
1 files changed, 13 insertions, 0 deletions
diff --git a/users/sterni/exercises/aoc/2022/20/20.bqn b/users/sterni/exercises/aoc/2022/20/20.bqn
new file mode 100644
index 000000000000..8d4c905e8749
--- /dev/null
+++ b/users/sterni/exercises/aoc/2022/20/20.bqn
@@ -0,0 +1,13 @@
+⟨ReadDec⟩ ← •Import "../../lib.bqn"
+enc ← ReadDec¨ •FLines "input"
+
+CoordSum ← +´∘(1000‿2000‿3000⊸((⊢≠⊸|+⟜(⊑∘(/=⟜0)∘⊢))⊏⊢))
+Mix ← {
+  M ← {m 𝕊 i:
+    l ← ≠m
+    i {n ← (l-1)|(𝕩⊑m)+⊑/𝕩=𝕨 ⋄ (n⊸↑(∾⟜𝕩)⊸∾n⊸↓) 𝕩(≠/⊢)𝕨}˜´ ⌽↕l
+  }
+  CoordSum ((⊢M⍟𝕨↕∘≠)⊏⊢) 𝕩
+}
+•Out "day20.1: "∾•Fmt 1 Mix enc
+•Out "day20.2: "∾•Fmt 10 Mix 811589153×enc