diff options
Diffstat (limited to 'users/sterni')
-rwxr-xr-x | users/sterni/exercises/aoc/2021/solutions.bqn | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/users/sterni/exercises/aoc/2021/solutions.bqn b/users/sterni/exercises/aoc/2021/solutions.bqn index d965e6047fe6..7aac53b9eaa7 100755 --- a/users/sterni/exercises/aoc/2021/solutions.bqn +++ b/users/sterni/exercises/aoc/2021/solutions.bqn @@ -13,6 +13,8 @@ ReadInput ← {•file.Lines ∾ •path‿"/input/day"‿(•Fmt 𝕩)} SplitOn ← ((⊢ (-1˙)⍟⊣¨ +`)∘=⊔⊢) +_fix ← {𝕩 𝕊∘⊢⍟≢ 𝔽 𝕩} + # # 2021-12-01 # @@ -148,3 +150,39 @@ FuelConsumption2 ← +˝∘(TriNum¨)∘|∘(-⌜) ! 168 = FuelConsumption2 _lowestFuelPossible day6ExampleData •Out "Day 7.2: "∾•Fmt FuelConsumption2 _lowestFuelPossible day6Input + +# +# 2021-12-09 +# + +# part 1 + +ParseHeightMap ← ((≠≍(≠⊑))⥊∾)∘-⟜'0' + +day9ExampleData ← ParseHeightMap ⟨ + "2199943210", + "3987894921", + "9856789892", + "8767896789", + "9899965678" +⟩ +day9Input ← ParseHeightMap ReadInput 9 + +Rotate ← (⍉⌽)∘⊢⍟⊣ # counter clockwise +LowPoints ← {∧´𝕩⊸(⊣<((-⊢) Rotate ∞⊸»˘∘Rotate˜))¨ ↕4} + +RiskLevelSum ← (+´⥊)∘(1⊸+×LowPoints) + +! 15 = RiskLevelSum day9ExampleData + +•Out "Day 9.1: "∾•Fmt RiskLevelSum day9Input + +# part 2 + +NumberBasins ← ((1⊸+⊒⌾⥊)×⊢)∘LowPoints +Basins ← {𝕩⊸((<⟜9⊣)∧(«⌈»⌈«˘⌈»˘⌈⊢)∘⊢) _fix NumberBasins 𝕩} +LargestBasinsProduct ← {×´ 3↑ ∨ 1↓ ≠¨ ⊔⥊Basins 𝕩} + +! 1134 = LargestBasinsProduct day9ExampleData + +•Out "Day 9.2: "∾•Fmt LargestBasinsProduct day9Input |