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

  • mykl@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    30 days ago

    Uiua

    Just a messy part1 so far. Plus a moment of pure rage when I realised the trap. (I have no idea what algorithm Lemmy uses to highlight Uiua code, but it’s always a surprise.)

    (edit: part 2 now added. I had a stupid error earlier. Takes 12s native or 20+s in the pad.)

    Stupid error

    I added elements just until the set first hit size 1, rather than continuing until total number of elements equalled number of points.

    Run it here(for what it’s worth)

    # AOC 2025 Day 08
    "162,817,812\n57,618,57\n906,360,560\n592,479,940\n352,342,300\n466,668,158\n542,29,236\n431,825,988\n739,650,466\n52,470,668\n216,146,977\n819,987,18\n117,168,530\n805,96,715\n346,949,466\n970,615,88\n941,993,340\n862,61,35\n984,92,344\n425,690,689"
    N  10
    L  20
    # &fras"AOC2025day08.txt" # Uncomment these three lines,
    # N  1000                 # drop your file onto this pane and correct that
    # L  1000                 # filename, to run this against your data.
    # You will need to change settings>execution time to 30s or more.
    
    Row  (
      (⊃⊢↘₁)
      ⊚◡≡⌟◇(/+˜)
      (⊂⊙□◌                     # Not found: new circuit
      | ⍜⊡(⍜°□(◴⊂))             # One found: add
      | ▽>⊸≡◇⧻⍜(⊏|⊂{[]}{}◴/◇⊂) # Connect two
      )⊸⧻◴
    )
    Parse      ⍆⋕°csv
    Sort       ⊏⍏/+2/-⊸⍉⊸⧅>2
    IndexPrep  {[°⊟]}⊸°⊂⊸≡⌟₁˜
    Part₁      ⊙◌/×↙3⇌⍆≡◇⧻⍥Row(-1N)
    Part₂      /×⊢⍉⊏⊣↘¯⧻◌⍢(Row|<L/+≡◇⧻)
    
    (&pnowPart₁)(&pnowPart₂) &pnow(IndexPrep Sort Parse)
    
    • Strlcpy@1@lemmy.sdf.org
      link
      fedilink
      English
      arrow-up
      3
      ·
      1 month ago

      the trap

      Re. what connections to process or not? That seems to be like one of those that’s either completely obvious when you implement your solution one way, and a nasty pitfall when you do it another. In this case, pre-computing the list of pairs to process vs. finding the next one when you need it.

      • mykl@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        1 month ago
        spoiler

        Stupider than that: I’d just got halfway through writing a complicated divide and conquer algorithm to calculate nearest pairs when I realised that I could just brute-force it. :-)

        But yes, precomputing was definitely the way to go.