about summary refs log tree commit diff
path: root/users/sterni
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2021-12-15T23·46+0100
committersterni <sternenseemann@systemli.org>2021-12-15T23·58+0000
commitb5678cbd5f55e2f3f96a1d67cb07c3545a6c9ffe (patch)
tree1c836469d396f362bf9f54e13ff0f674ca4070e5 /users/sterni
parent3f8c99f5c33632b0e69bc3334793eabf847c48f8 (diff)
feat(sterni/aoc/2021): day 14 solution r/3263
Change-Id: I8b6c0c5d1ced89eadaeea3fb619d37e77a439965
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4349
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'users/sterni')
-rwxr-xr-xusers/sterni/exercises/aoc/2021/solutions.bqn33
1 files changed, 33 insertions, 0 deletions
diff --git a/users/sterni/exercises/aoc/2021/solutions.bqn b/users/sterni/exercises/aoc/2021/solutions.bqn
index 47e858cff588..f240e7dc2d11 100755
--- a/users/sterni/exercises/aoc/2021/solutions.bqn
+++ b/users/sterni/exercises/aoc/2021/solutions.bqn
@@ -245,3 +245,36 @@ DotMatrix ← {
 
 •Out "Day 13.2:"
 •Out •Fmt DotMatrix day13Folds PerformAllFolds day13Dots
+
+#
+# 2021-12-14
+#
+
+day14Polymer ← ⊑ReadInput 14
+day14Mapping ← 2↓ReadInput 14
+
+lp ← (2⊸↑)¨ day14Mapping
+le ← ⍷∾lp
+
+# returns array as long as 𝕨 detailing how many times the element
+# at any given index occurs in 𝕩.
+Counts ← ((≠⊣)↑(/⁼)∘⊐)
+
+deltaPairs ← {
+  addedPairs ← ((-1)⊸⊑¨day14Mapping) (⌽⌾(0⊸⊑))∘(∾¨)¨ lp
+  removedPairs ← ⋈¨ (2⊸↑)¨ lp
+  addedPairs (-○(lp⊸Counts))¨ removedPairs
+}
+
+pairCount ← lp Counts ⥊∘(⋈˘) 2↕day14Polymer
+
+PairInsert ← {𝕩 +´ 𝕩רdeltaPairs}
+
+pairElementCount ← (le⊸Counts)¨lp
+
+ElementRarityDiff ← {
+ ((-1)⊸⊑-⊑)∧ ⌈2÷˜ +´ pairElementCount×PairInsert⍟𝕩 pairCount
+}
+
+•Out "Day 14.1: "∾•Fmt ElementRarityDiff 10
+•Out "Day 14.2: "∾•Fmt ElementRarityDiff 40