diff options
author | sterni <sternenseemann@systemli.org> | 2021-12-09T15·51+0100 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2021-12-13T21·13+0100 |
commit | 464bbcb15c09813172c79820bcf526bb10cf4208 (patch) | |
tree | 654b11672a0aacf66b90e4634200015298e2a9fb /users/sterni/exercises/aoc | |
parent | 343b811bbc31aea07719a0676fa960b1204cd5e8 (diff) |
feat(sterni/aoc/2021): day 9 solution r/3225
Change-Id: I90e7a47d5418abeff1ae7cc5757b6a8b3b0d1086
Diffstat (limited to 'users/sterni/exercises/aoc')
-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 |