From d44b57b6419ead9fcecaf86b5ef90ba06de17331 Mon Sep 17 00:00:00 2001 From: sterni Date: Fri, 24 Dec 2021 18:11:00 +0100 Subject: feat(sterni/aoc/2021): day 20 solution Change-Id: Id864d6e6f0722c2da5d3487bd38da80e6bff2161 Reviewed-on: https://cl.tvl.fyi/c/depot/+/4566 Tested-by: BuildkiteCI Reviewed-by: sterni --- users/sterni/exercises/aoc/2021/solutions.bqn | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'users/sterni/exercises') 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 -- cgit 1.4.1