diff options
author | sterni <sternenseemann@systemli.org> | 2021-12-04T00·09+0100 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2021-12-13T20·58+0100 |
commit | 4b38ba2d0a916309351ca06cb1f20b8bca417366 (patch) | |
tree | 428cb2b84dcbc1e2fdbdf6e6dfa265fc8c2ef8fc /users/sterni/exercises | |
parent | b97d6b0f1b2bc9576586dca996acba59bf8e445c (diff) |
feat(sterni/aoc/2021): day 2 "solution" r/3221
Change-Id: Ifbd50274f0b09305991a49e7453ac1f13089e57e
Diffstat (limited to 'users/sterni/exercises')
-rwxr-xr-x | users/sterni/exercises/aoc/2021/solutions.bqn | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/users/sterni/exercises/aoc/2021/solutions.bqn b/users/sterni/exercises/aoc/2021/solutions.bqn index 98d70f8f15cf..463b38543f04 100755 --- a/users/sterni/exercises/aoc/2021/solutions.bqn +++ b/users/sterni/exercises/aoc/2021/solutions.bqn @@ -4,9 +4,11 @@ # Utilities # +IsAsciiNum ← ('0'⊸≤∧≤⟜'9') + ReadInt ← (10⊸×+⊣)´∘⌽-⟜'0' # stolen from leah2 -ReadInput ← {ReadInt¨•file.Lines ∾ •path‿"/input/day"‿(•Fmt 𝕩)} +ReadInput ← {•file.Lines ∾ •path‿"/input/day"‿(•Fmt 𝕩)} # # 2021-12-01 @@ -15,6 +17,7 @@ ReadInput ← {ReadInt¨•file.Lines ∾ •path‿"/input/day"‿(•Fmt 𝕩) # part 1 day1ExampleData ← 199‿200‿208‿210‿200‿207‿240‿269‿260‿263 +day1Input ← ReadInt¨ReadInput 1 # NB: Because distance from the ground is never smaller than zero, it's # no problem that nudge inserts a zero at the end of the right list @@ -22,10 +25,45 @@ PositiveDeltaCount ← +´∘(⊢<«)+˝˘∘↕ ! 7 = 1 PositiveDeltaCount day1ExampleData -•Out "Day 1.1: "∾•Fmt 1 PositiveDeltaCount ReadInput 1 +•Out "Day 1.1: "∾•Fmt 1 PositiveDeltaCount day1Input # part 2 ! 5 = 3 PositiveDeltaCount day1ExampleData -•Out "Day 1.2: "∾•Fmt 3 PositiveDeltaCount ReadInput 1 +•Out "Day 1.2: "∾•Fmt 3 PositiveDeltaCount day1Input + +# +# 2021-12-02 +# + +# part 1 + +day2ExampleData ← ⟨ + "forward 5", + "down 5", + "forward 8", + "up 3", + "down 8", + "forward 2", +⟩ + +day2Input ← ReadInput 2 + +ParseSubmarineCommand ← (((↕2)⊸((((-1)⊸⋆)∘(2⊸|))×(=⟜(⌊∘(÷⟜2))))∘("duf"⊸⊐)∘⊑)×ReadInt∘(IsAsciiNum/⊢)) + +SubmarineDestProduct ← {×´+´ParseSubmarineCommand¨𝕩} + +! 150 = SubmarineDestProduct day2ExampleData + +•Out "Day 2.1: "∾•Fmt SubmarineDestProduct day2Input + +# part 2 + +SubmarineAimedDestProduct ← { + ×´+´((×´)∘(1⊸↓)≍(1⊸⊑))¨ (<0‿0‿0) (⊢∾((⊑∘⌽⊣)+(⊑⊢)))` ParseSubmarineCommand¨𝕩 +} + +! 900 = SubmarineAimedDestProduct day2ExampleData + +•Out "Day 2.2: "∾•Fmt SubmarineAimedDestProduct day2Input |