about summary refs log tree commit diff
path: root/users/sterni/exercises/aoc/2021
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2021-12-16T12·40+0100
committerclbot <clbot@tvl.fyi>2021-12-16T12·43+0000
commit01f4212ca184c9be40b84a3f9365c17796d6b6f3 (patch)
treeb52748785c2bed900379cd67dc1e93f5549d6d51 /users/sterni/exercises/aoc/2021
parent0357dd973bd63b73158c6886f2e92a793adbfff8 (diff)
feat(sterni/aoc/2021): day 15 solution r/3265
Change-Id: Idca2ae2829a7ee9e856aa7fcdc716c3055051062
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4363
Reviewed-by: sterni <sternenseemann@systemli.org>
Autosubmit: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/sterni/exercises/aoc/2021')
-rwxr-xr-xusers/sterni/exercises/aoc/2021/solutions.bqn35
1 files changed, 35 insertions, 0 deletions
diff --git a/users/sterni/exercises/aoc/2021/solutions.bqn b/users/sterni/exercises/aoc/2021/solutions.bqn
index f240e7dc2d11..83949daa118b 100755
--- a/users/sterni/exercises/aoc/2021/solutions.bqn
+++ b/users/sterni/exercises/aoc/2021/solutions.bqn
@@ -278,3 +278,38 @@ ElementRarityDiff ← {
 
 •Out "Day 14.1: "∾•Fmt ElementRarityDiff 10
 •Out "Day 14.2: "∾•Fmt ElementRarityDiff 40
+
+#
+# 2021-12-15
+#
+
+day15ExampleInput ← >⟨
+  1‿1‿6‿3‿7‿5‿1‿7‿4‿2
+  1‿3‿8‿1‿3‿7‿3‿6‿7‿2
+  2‿1‿3‿6‿5‿1‿1‿3‿2‿8
+  3‿6‿9‿4‿9‿3‿1‿5‿6‿9
+  7‿4‿6‿3‿4‿1‿7‿1‿1‿1
+  1‿3‿1‿9‿1‿2‿8‿1‿3‿7
+  1‿3‿5‿9‿9‿1‿2‿4‿2‿1
+  3‿1‿2‿5‿4‿2‿1‿6‿3‿9
+  1‿2‿9‿3‿1‿3‿8‿5‿2‿1
+  2‿3‿1‿1‿9‿4‿4‿5‿8‿1
+⟩
+day15Input ← '0'-˜ ((≠⋈≠∘⊑)⥊∾)ReadInput 15
+
+LowestRiskLevel ← {
+  start ← 0˙⌾⊑ (⥊⟜∞) ≢𝕩
+  ir ← (1⊑≢𝕩)⥊∞
+  Step ← {𝕩 ⌊ 𝕨 + (ir⊸«⌊ir⊸»⌊∞⊸«˘⌊∞⊸»˘) 𝕩}
+  ⊑⌽⥊ 𝕩⊸Step _fix start
+}
+
+! 40 = LowestRiskLevel day15ExampleInput
+
+•Out "Day 15.1: "∾•Fmt LowestRiskLevel day15Input
+
+FiveByFiveMap ← {(9⊸|)⌾(-⟜1) ∾(<𝕩)+ +⌜˜↕5}
+
+! 315 = LowestRiskLevel FiveByFiveMap day15ExampleInput
+
+•Out "Day 15.2: "∾•Fmt LowestRiskLevel FiveByFiveMap day15Input