about summary refs log tree commit diff
path: root/users/sterni/exercises/aoc/2021/solutions.bqn
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2021-12-24T17·11+0100
committersterni <sternenseemann@systemli.org>2021-12-25T11·18+0000
commitd44b57b6419ead9fcecaf86b5ef90ba06de17331 (patch)
tree4251c146c499402db10854732072d942ffc5bc18 /users/sterni/exercises/aoc/2021/solutions.bqn
parent4fbb2a16581535412d7b9fde356eb97f7ce62118 (diff)
feat(sterni/aoc/2021): day 20 solution r/3390
Change-Id: Id864d6e6f0722c2da5d3487bd38da80e6bff2161
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4566
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'users/sterni/exercises/aoc/2021/solutions.bqn')
-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 4b6eef823262..ea611e666f31 100755
--- a/users/sterni/exercises/aoc/2021/solutions.bqn
+++ b/users/sterni/exercises/aoc/2021/solutions.bqn
@@ -328,3 +328,32 @@ FiveByFiveMap ← {(9⊸|)⌾(-⟜1) ∾(<𝕩)+ +⌜˜↕5}
 ! 315 = LowestRiskLevel FiveByFiveMap day15ExampleInput
 
 •Out "Day 15.2: "∾•Fmt LowestRiskLevel FiveByFiveMap day15Input
+
+#
+# 2021-12-20
+#
+
+ParsePic ← (⋈⟜0)∘('#'⊸=)∘>
+
+day20ExampleAlgo ← '#'="..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..#"
+day20ExamplePic ← ParsePic ⟨"#..#.", "#....", "##..#", "..#..", "..###"⟩
+day20Input ← ReadInput 20
+day20Algo ← '#'=⊑day20Input
+day20Pic ← ParsePic 2↓day20Input
+
+GrowAxis ← {(⊢ (-1)⊸⌽∘∾ (⥊⟜𝕨)∘(2˙⌾⊑)∘≢) 𝕩}
+Grow ← {𝕨 GrowAxis 𝕨 GrowAxis˘ 𝕩}
+
+Enhance ← {
+  inf ← 1⊑𝕩
+  npic ← ((⊑⟜𝕨)∘DebinList∘⥊)˘˘ 3‿3↕ (inf⊸Grow)⍟2 ⊑𝕩
+  ninf ← 𝕨⊑˜511×inf
+  npic⋈ninf
+}
+_EnhancedPixelCount ← {+´⥊⊑ (𝕨⊸Enhance)⍟𝕗 𝕩}
+
+! 35 = day20ExampleAlgo 2 _EnhancedPixelCount day20ExamplePic
+! 3351 = day20ExampleAlgo 50 _EnhancedPixelCount day20ExamplePic
+
+•Out "Day 20.1: "∾•Fmt day20Algo 2 _EnhancedPixelCount day20Pic
+•Out "Day 20.2: "∾•Fmt day20algo 50 _EnhancedPixelCount day20Pic