Day 7: Bridge Repair

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

  • Quant@programming.dev
    link
    fedilink
    arrow-up
    3
    ·
    15 days ago

    Uiua

    Credits to @mykl@lemmy.world for the approach of using reduce and also how to split the input by multiple characters.
    I can happily say that I learned quite a bit today, even though the first part made me frustrated enough that I went searching for other approaches ^^

    Part two just needed a simple modification. Changing how the input is parsed and passed to the adapted function took longer than changing the function itself actually.

    Run with example input here

    PartOne ← (
      &rs ∞ &fo "input-7.txt"
      ⊜□≠@\n.
      ≡◇(⊜□≠@:.)
      ≡⍜⊡⋕0
      ≡⍜(°□⊡1)(⊜⋕≠@ .)
      ⟜(⊡0⍉)
    
      # own attempt, produces a too low number
      # ≡(:∩°□°⊟
      #   ⍣(⍤.◡⍣(1⍤.(≤/×)⍤.(≥/+),,)0
      #     ⊙¤⋯⇡ⁿ:2-1⊸⧻
      #     ⊞(⍥(⟜⍜(⊙(↙2))(⨬+×⊙°⊟⊡0)
      #         ↘1
      #       )⧻.
      #       ⍤.=0⧻.
      #     )
      #     ∈♭◌
      #   )0)
    
      # reduce approach found on the programming.dev AoC community by mykl@lemmy.world
      ≡(◇(∈/(◴♭[⊃(+|×)]))⊡0:°⊂)
      °□/+▽
    )
    
    PartTwo ← (
      &rs ∞ &fo "input-7.txt"
      ⊜(□⊜⋕¬∈": ".)≠@\n.
      ⟜≡◇⊢
      ≡◇(∈/(◴♭[≡⊃⊃(+|×|⋕$"__")]):°⊂)
      °□/+▽
    )
    
    &p "Day 7:"
    &pf "Part 1: "
    &p PartOne
    &pf "Part 2: "
    &p PartTwo