about summary refs log tree commit diff
path: root/users/sterni/exercises/aoc
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2021-12-07T18·05+0100
committersterni <sternenseemann@systemli.org>2021-12-13T20·58+0100
commit343b811bbc31aea07719a0676fa960b1204cd5e8 (patch)
tree2487e4d09e9d13bbd4588b1385328f78f5325c13 /users/sterni/exercises/aoc
parentf78a7467f1135ddf2fec2c257f28887879742903 (diff)
feat(sterni/aoc/2021): day 7 solution r/3224
Change-Id: I8c8b535defb42f15eafc816ebe953e51b11ea702
Diffstat (limited to 'users/sterni/exercises/aoc')
-rwxr-xr-xusers/sterni/exercises/aoc/2021/solutions.bqn29
1 files changed, 29 insertions, 0 deletions
diff --git a/users/sterni/exercises/aoc/2021/solutions.bqn b/users/sterni/exercises/aoc/2021/solutions.bqn
index 4a1f4668d11f..d965e6047fe6 100755
--- a/users/sterni/exercises/aoc/2021/solutions.bqn
+++ b/users/sterni/exercises/aoc/2021/solutions.bqn
@@ -11,6 +11,8 @@ ReadDec ← 10⊸ReadInt
 
 ReadInput ← {•file.Lines ∾ •path‿"/input/day"‿(•Fmt 𝕩)}
 
+SplitOn ← ((⊢ (-1˙)⍟⊣¨ +`)∘=⊔⊢)
+
 #
 # 2021-12-01
 #
@@ -119,3 +121,30 @@ CO2ScrubberRating ← DebinList 0 >_lifeSupportRating ⊢
 ! 10 = CO2ScrubberRating day3ExampleData
 
 •Out "Day 3.2: "∾•Fmt (OxygenGeneratorRating×CO2ScrubberRating) day3Input
+
+#
+# 2021-12-07
+#
+
+# part 1
+
+day6ExampleData ← ⟨16,1,2,0,4,2,7,1,2,14⟩
+day6Input ← ReadDec¨ ','  SplitOn ⊑ReadInput 6
+
+PossiblePositions ← (⌊´+⟜(↕1⊸+)⌈´)
+FuelConsumption ← +˝∘|∘(-⌜)
+_lowestFuelPossible ← {⌊´∘(𝔽⟜PossiblePositions)˜ 𝕩}
+
+! 37 = FuelConsumption _lowestFuelPossible day6ExampleData
+
+•Out "Day 7.1: "∾•Fmt FuelConsumption _lowestFuelPossible day6Input
+
+# part 2
+
+TriNum ← 1⊸+×÷⟜2
+
+FuelConsumption2 ← +˝∘(TriNum¨)∘|∘(-⌜)
+
+! 168 = FuelConsumption2 _lowestFuelPossible day6ExampleData
+
+•Out "Day 7.2: "∾•Fmt FuelConsumption2 _lowestFuelPossible day6Input