diff options
author | sterni <sternenseemann@systemli.org> | 2021-12-07T10·02+0100 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2021-12-13T20·58+0100 |
commit | f78a7467f1135ddf2fec2c257f28887879742903 (patch) | |
tree | 326d6a698c9be9454e86e5dbc64b602f93415b47 /users | |
parent | b3d43057005b3bae13e113288d59a0d0941c3ded (diff) |
feat(sterni/aoc/2021): day 3 solution r/3223
Change-Id: Id14281f7b18ddaf6875e5dd8398249a10a9474af
Diffstat (limited to 'users')
-rwxr-xr-x | users/sterni/exercises/aoc/2021/solutions.bqn | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/users/sterni/exercises/aoc/2021/solutions.bqn b/users/sterni/exercises/aoc/2021/solutions.bqn index 3a3dc82ac05e..4a1f4668d11f 100755 --- a/users/sterni/exercises/aoc/2021/solutions.bqn +++ b/users/sterni/exercises/aoc/2021/solutions.bqn @@ -68,3 +68,54 @@ SubmarineAimedDestProduct ← { ! 900 = SubmarineAimedDestProduct day2ExampleData •Out "Day 2.2: "∾•Fmt SubmarineAimedDestProduct day2Input + +# +# 2021-12-03 +# + +BinTable ← '0'-˜> + +day3ExampleData ← BinTable ⟨ + "00100", + "11110", + "10110", + "10111", + "10101", + "01111", + "00111", + "11100", + "10000", + "11001", + "00010", + "01010", +⟩ + +day3Input ← BinTable ReadInput 3 + +DeBinList ← ((2⊸×)+⊣)´⌽ +_tableAggr ← {((÷⟜2)∘(/⟜⥊)´∘⌽∘≢𝔽(+˝))𝕩} +GammaRate ← < _tableAggr + +! 22 = DeBinList GammaRate day3ExampleData +! 9 = DeBinList ¬GammaRate day3ExampleData + +•Out "Day 3.1: "∾•Fmt (¬×○DeBinList⊢) GammaRate day3Input + +_lifeSupportRating ← { + # Need to rename the arguments, otherwise the ternary expr becomes a function + bitPos ← 𝕨 + Cmp ← 𝔽 + + crit ← Cmp _tableAggr 𝕩 + matchPos ← bitPos ⊑˘ crit ((⥊˜⟜≢)=⊢) 𝕩 + match ← matchPos/𝕩 + {1=≠match?⊏match;(bitPos+1) Cmp _lifeSupportRating match} +} + +OxygenGeneratorRating ← DeBinList 0 ≤_lifeSupportRating ⊢ +CO2ScrubberRating ← DebinList 0 >_lifeSupportRating ⊢ + +! 23 = OxygenGeneratorRating day3ExampleData +! 10 = CO2ScrubberRating day3ExampleData + +•Out "Day 3.2: "∾•Fmt (OxygenGeneratorRating×CO2ScrubberRating) day3Input |