this post was submitted on 08 Dec 2025
21 points (100.0% liked)

Advent Of Code

1200 readers
2 users here now

An unofficial home for the advent of code community on programming.dev! Other challenges are also welcome!

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

Everybody Codes is another collection of programming puzzles with seasonal events.

EC 2025

AoC 2025

Solution Threads

M T W T F S S
1 2 3 4 5 6 7
8 9 10 11 12

Visualisations Megathread

Rules/Guidelines

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

founded 2 years ago
MODERATORS
 

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
[–] Quant@programming.dev 3 points 2 weeks 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