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

you are viewing a single comment's thread
view the rest of the comments
[–] 3 points 9 months 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

  • source