Day 8: Playground

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
    ·
    22 days ago

    Uiua

    Not really proud of this one. Part 1’s still ok, just calculated all distances between boxes after realizing it’s not that many (499500, a reasonable amount I think, relatively speaking).
    The dumbest thing I did this time was manually implementing the function to take the first n rows of an array by using a loop. Only when I was working on part 2 did I realize that I can just use the “take” function Uiua provides. Additionally, I even had some mistake in my reimplementation of it that only caused issues in part 2 somehow.
    For anyone interested, it’s the commented out line in P₁ below.
    Part 2 is just a brute force. For the actual input, I searched manually until I got to the pair number just before the actual solution because I didn’t want it to run that long and it takes long enough as is.

    Run with example input

    Code
    $ 162,817,812
    $ 57,618,57
    $ 906,360,560
    $ 592,479,940
    $ 352,342,300
    $ 466,668,158
    $ 542,29,236
    $ 431,825,988
    $ 739,650,466
    $ 52,470,668
    $ 216,146,977
    $ 819,987,18
    $ 117,168,530
    $ 805,96,715
    $ 346,949,466
    $ 970,615,88
    $ 941,993,340
    $ 862,61,35
    $ 984,92,344
    $ 425,690,689
    
    Dist ← ⍜(≡°√)/+⌵-°⊟
    Prep ← (
      ⊜(⊜⋕⊸≠@,)⊸≠@\n
      ⧅<2
      ⊏⍏⊸≡Dist
    )
    
    Merge ← (
      ⍜♭₂⊛
      {}
      ⍥(⍣(⊙(°⊂
            □⍥(
              ⟜⊸˜≡⌟(>/+⊃⨂(×₂⋅⧻))
              ◴⊂⊙(♭∩⌟▽⟜¬)
            )∞
          )
          ⊂
        | ∘)
      )∞
      ⊙◌
    )
    
    P₁ ← (
      Prep
      # ⍥₁₀(⊙⤙⊡°˜⊂)
      ↙₁₀
      Merge
      ⍆≡◇⧻
      /×↙₋₃
    )
    
    P₂ ← (
      Prep
      1_0
      ⊸⍢(
        ⍜°˜⊟(
          ⊙+₁
          ⋅⟜↙
          ⊙(Merge
            ◇⧻⊢)
        )
      | <20⊣)
      -₁⊢
      ⊡
      ×°⊟⊡₀⍉
    )
    
    [⊃P₁P₂]
    ≡(&p $"Part _: _") 1_2