Day 5: Cafeteria

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
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    7 months ago

    It turns out that merging isn’t necessary, it’s simpler and slightly faster to just sort by starts. Part 2 then needs to remove any overlaps between adjacent ranges by setting end of each to min(end of this, start of next-1).

    # AOC 2025 day 5
    # D  "3-5\n10-14\n16-20\n12-18\n\n1\n5\n8\n11\n17\n32"
    D      &fras"2025day05.txt"            # drop your input file on this pane and uncomment this line to test against your own data.
    Parse  °⊟⍉⍆↯∞_2(⊜⋕⊸∊+@010)°$"_\n\n_" # split at \n\n; find all digits; sort ranges.
    
    P₁  /+≡(/)↧⊓⌟≥≤∩¤       # compare each against start/end arrays
    P₂  ⊙◌/+-⟜(↧⊓⬚∞↻₁(+1\)) # unmerge the ranges! simpler to count.
    now (P₁ P₂ Parse D)