about summary refs log tree commit diff
path: root/day24.bqn
diff options
context:
space:
mode:
Diffstat (limited to 'day24.bqn')
-rw-r--r--day24.bqn22
1 files changed, 22 insertions, 0 deletions
diff --git a/day24.bqn b/day24.bqn
new file mode 100644
index 0000000..b1df09a
--- /dev/null
+++ b/day24.bqn
@@ -0,0 +1,22 @@
+# port of https://github.com/cettt/Advent_of_Code2021/blob/master/day_24.R
+str←•Import"bqn-libs/strings.bqn"
+Diff ← (¬∘∊/⊣)
+
+d←{•BQN⊑⌽" " str.Split 𝕩}¨ 4‿5‿15 ⊏⎉1 14‿∘⥊•FLines"day24"
+
+x1←eqidx←/9≥1⊏˘d
+x2←⟨⟩
+x1minmax←⟨⟩
+x2minmax←⟨⟩
+
+{
+  x2 ∾↩ newmatch ← ⌈´ (↕𝕩) Diff x1∾x2
+  b ← (newmatch‿2⊑d) + 𝕩‿1⊑d
+  minmax ← (0 (<⋈>) b) + (⌊´⋈⌈´) / (>⟜0 ∧ <⟜10) b+↕9
+  x2minmax ∾↩ <minmax
+  x1minmax ∾↩ <minmax+b
+}¨eqidx
+
+res←(x1∾˘>x1minmax)∾(x2∾˘>x2minmax)
+
+•Show '0'+⌽⍉1↓˘(⍋0⊏˘res)⊏res