Skip Navigation

Posts
15
Comments
200
Joined
3 yr. ago

  • Obviously very spoilery code, if you dare read it closely. try it here

    It feels very anticlimactic to be ending so early in the month, but see you all next year!

     
        
    # AOC 2025 day 12 - Packing parcels
    ▽⊸≡◇˜∊@x⊜□⊸≠@\n&fras"AOC2025day12.txt"
    /+<⊙×₉≡◇(⊓/×/+⊃↙↘2⊜⋕¬⊸∊": x")
    
    
      
  • huh?

     
        
    ⇌+@A×4+5˜⊂0+3⊂0[+1⊸˙×2]
    
      
  • Yes, it felt a little more like I was solving the puzzle-setter rather than the puzzle today.

  • There’s so many great features hidden behind ‘un’.

    I’m sure that part2 could be simplified significantly but I was fed up by then.

  • Uiua

    If it's stupid but it works...

    I broke the maze into SVR>FFT>DAC>OUT and SVR>DAC>FFT>OUT, realised that the latter was taking a suspiciously long time, so submitted just the answer from the former --> success!

    link (You'll need to up the execution limit)

     
        
    # AOC2025day11 - mazes.
    # Uncomment for Part 1
    D ← "aaa: you hhh\nyou: bbb ccc\nbbb: ddd eee\nccc: ddd eee fff\nddd: ggg\neee: out\nfff: out\nggg: out\nhhh: ccc fff iii\niii: out"
    # Uncomment for Part 2
    # D ← "svr: aaa bbb\naaa: fft\nfft: ccc\nbbb: tty\ntty: ccc\nccc: ddd eee\nddd: hub\nhub: fff\neee: dac\ndac: fff\nfff: ggg hhh\nggg: out\nhhh: out"
    # D      ← &fras "randomAOC/AOC2025day11.txt"
    Tabs   ← ⊜(⊙□°⊂⊜∘¬⊸∊": ")⊸≠@\nD
    Nexts  ← ⍣(°□⊡˜⨂⊙Tabs|[])
    Part₁  ← ⊙◌⧻path(˙≠°⊏Nexts|≍"out")"you"
    
    Part₂ ← (
      ⊙◌⧻path(˙≠°⊏Nexts|≍"fft")"svr"
      ⊙◌⧻path(˙≠°⊏Nexts|≍"dac")"fft"
      ⊙◌⧻path(˙≠°⊏Nexts|≍"out")"dac"
      ××
    )
    # Only one will be right for the test data, depending on dataset.
    ⊃Part₁ Part₂
    
      
  • I'm getting PTSD from today now.

  • Uiua

    (added language tag)

    Quiet here, isn't it?

    Here's part1 to be going on with.

     
        
    # AOC 2025 Day 10 - Wiring maze
    D ← "[.##.] (3) (1,3) (2) (2,3) (0,2) (0,1) {3,5,4,7}\n[...#.] (0,2,3,4) (2,3) (0,4) (0,1,2) (1,2,3,4) {7,5,12,7,2}\n[.###.#] (0,1,2,3,4) (0,3,4) (0,1,2,4,5) (1,2) {10,11,11,5,10,5}"
    # D      ← &fras"randomAOC/AOC2025day10.txt"
    Digits ← ⊜⋕⊸∊+@0⇡10
    Parse  ← ⊜(□⊜□⊸≠@\s)⊸≠@\n
    Part₁ ← (
      ≡◇(
        =@#↘₁↘₋₁°□°⊂↘¯1  # target
        ⊙⬚0≡◇(°⊚Digits)  # presses
        ⧻⊢path(≡⌞≠|=0/+) # find shortest path
      )
      /+-1
    )
    Part₁ Parse D
    
      

    I've given up on Part 2. I knew what I needed to do but didn't have the understanding of how to use the matrix elimination method to get beyond the first stages. But I did find this:

    This is a solver written totally from scratch in Dart, so easily readable unlike some other languages :-): [https://github.com/ayoubzulfiqar/advent-of-code/blob/main/2025/Dart/Day10/part_2.dart](GitHub link)

    There's lots of parallelism (that's over the top for this problem), but the core solveSystem method is very clearly written, just long...

  • Squeezing all spaces out of the grid (and plotting at right-angles to the other visualisation here) gives this evil shape, which will doubtless haunt my dreams tonight.

  • Uiua

    Part 1 was easy, part 2 is ...less so...

    visualising the data reveals some interesting patterns. Follow link to do so.

    Any way, here's my Part 1 while I'm still thinking about this.

     
        
    # AOC 2025 Day 09
    # Experimental!
    D ← &fras"AOC2025day09.txt"  # Drop your file here and edit name
    /↥/×+1⌵⍉/-⍉₂⧅<2⋕°csv D       # Part 1 
    ∧⍜⊡⋅1⟜(˜↯0+1/↥)⍜⍉≡⍜⍆⊛⋕°csv D # Visualised data
    
      

    Part 2

    This is basically me thinking out loud, so it's untidy, brutal, repetitive and slow. (20s in the pad) link if you care

     
        
    # Experimental!
    # AOC 2025 Day 09
    D     ← "7,1\n11,1\n11,7\n9,7\n9,5\n2,5\n2,3\n7,3"
    D     ← &fras"AOC2025day09.txt" # Drop your file here and edit name
    Parse ← ⋕°csv
    Part₁ ← /↥/×+1⌵⍉/-⍉₂⧅<2
    
    Squeeze ← ⍜⍉≡⍜⍆⊛          # Squeeze (add a sort to inspect)
    Draw    ← ∧⍜⊡⋅1⟜(˜↯0+1/↥) # Draw
    
    HLines ← (
      Squeeze Parse D
      ⍆⊕(□⍆)⊛⊸≡⊢
      ∧◇(⍜⊡˜⍜(⊏|˙=)⊙˜∘⊃(⊢⊢|↘⊙⇡°⊟+0_1⊣⍉))
    )
    
    VLines ← (
      Squeeze Parse D
      ⍆⊕(□⍆)⊛⊸≡⊣
      ∧◇(⍜⊡˜⍜(⊏|˙=)⊙˜∘⊃(⊣⊣|↘⊙⇡°⊟+0_1⊢⍉))
    )
    DrawBorder ← ⍜⍉VLines HLines ˜↯0↯2+1/↥♭Squeeze Parse D # Draws full border
    
    # DrawBorder Squeeze # running this shows these as key boundary points -> [219 121] [219 123]
    # ⊏≡⌟˜⨂[[219 121] [219 123]]⊸Squeeze # which map to -> [[94985 48652][94985 50114]]
    # leftmost -> only look left, rightmost-> only look right
    # SO, now fill the shape to make this easier.
    Fill ← (
      ⊙⊙1           # fill colour.
      Good ← =0⊙◌⊡⊢ # Needs filling. Simple edges-check.
      # Take first of list. If needs fill, do so and then add
      # its four neighbours into queue. Repeat until queue is empty.
      ⍢(⨬(↘1|◴⊂+A₂¤°⊂ ⊃(⋅∘|∘|⋅⋅⋅∘)◡(⍜(⊡|⋅∘)⊢))◡Good
      | >0⧻)
      ⋅⊙⋅
    )
    DrawBorder     # Comment out everything below here to view the boundary.
    Fill [219_120] # Now fill that boundary ([2_1] for test)
    Squeeze Parse D
    # ([0 1] for test)
    [219 123] #  [219 121] gave the wrong answer, so it's this.
    ≡⌞⊟       # couple this with every other point
    # Extract the covered window of the array for each pair of corners.
    # (Very probably doing this the hard way:-()
    # Only keep those that are all 1.
    ▽⤚≡⌟(=1/×♭≡⌞⊏⊙⊏˜∘∩(↘⊙⇡°⊟+0_1⍆)°⊟⍉)
    # Pick out our squeezed indices
    ⨂Squeeze Parse D
    # Find out what the unsqueezed values were
    ˜⊏Parse D
    # Find areas, return max.
    /↥≡/×+1⌵≡/-
    
      
  • Yeah, that's one thing the gurus keep hammering home: anything you can move out of loop constructs (inc rows, partition, etc as well as the obvious do, repeat) and handle pervasively is a big win.

  • I'm more like the sorcerer's apprentice watching my arrays get increasingly out of my control :-)

  • 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.

  • When I compare it to some other Uiua solutions on the Discord I feel like I'm still just banging rocks together.

  • That certainly doesn't reflect my mood today.

  • Thanks, 'Tis the season.

  • 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.)

    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/+≡◇⧻)
    
    ⊃(&p⍜nowPart₁)(&p⍜nowPart₂) &p⍜now(IndexPrep Sort Parse)
    
      
  • If took more code to animate this than it did to solve the problem...

    Looks very nice for the test data:

    And...okay...for the live data:

  • Uiua

    A bit late getting to this, but happy with this solution, despite it being nothing more than just building/summing all paths. As usual, you can drop your own file onto that solution.

     
        
    D ← ".......S.......\n...............\n.......^.......\n...............\n......^.^......\n...............\n.....^.^.^.....\n...............\n....^.^...^....\n...............\n...^.^...^.^...\n...............\n..^...^.....^..\n...............\n.^.^.^.^.^...^.\n..............."
    # D ← &fras"AOC2025day07.txt" # <- Uncomment and drop file here.
    
    Parse ← ⊃↘↙1≠@.⊜∘⊸≠@\n
    Flow  ← ⊃(+⊃↻₁↻₋₁×|׬)⊙⊸⊣
    P₁    ← /+>0♭⬚0×⟜∧(˜⊂↥Flow)
    P₂    ← /+⊣∧(˜⊂+Flow)
    ⊃P₁ P₂ Parse D
    
      
  • Looks good. I like how you managed to use the same structure for Parts 1 and 2; that's more than I did. And yours is faster than mine too.

  • Uiua

    It took me a while to work out the merging of ranges, but I'm very pleased with the solution.

    Run it here

     
        
    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 ← ∩(⊜⋕⊸∊+@0⇡10)°□₂⊜□¬⊸⦷"\n\n"
    
    Merge ← ⨬(
      ⨬(⊟        # -> distinct, keep both.
      | ⊂⊢⟜(↥∩⊣) # -> overlap, merge them.
      )◡(≤⊓⊣⊢)
    | ⊙◌ # -> inside, ignore it.
    )◡(≤∩⊣)
    
    Ranges ← ⊙◌⍥⍜⊣(Merge⊙°⊂)◡⋅⧻⊃↙↘1⍆↯∞_2 # Merge pairs of ranges.
    
    P₁ ← /+≡⌞(/↥≡⌟(↧⊓⌟≥≤°⊟))
    P₂ ← /+≡(+1/-)⊙◌
    ⊃P₁ P₂ Ranges Parse D
    
      
  • Advent Of Code @programming.dev

    How's Part 2 going for you?

  • Advent Of Code @programming.dev

    Visualisation

    lazysoci.al /api/v3/image_proxy
  • Advent Of Code @programming.dev

    My CPU when I checked if part 1 code could solve part 2 (Day 11)

  • Advent Of Code @programming.dev

    How to speak to aliens (or read Uiua code)

  • Lemmy.world Support @lemmy.world
    Locked

    Requesting moderator status for adventofcode

  • Programming @programming.dev

    I'm posting a daily Dart solution to last year's Advent of Code challenges

    lemmy.world /post/7583249
  • Lemmy App Development @lemm.ee

    API call GetComments sometimes returns no comments

  • What is this thing? @lemmy.world

    CHALLENGE: What is this thing?

  • Geology @lemmy.ca

    Hello geologists, can you help us confirm if we're seeing a fossil in the linked post?

    lemmy.world /post/199064
  • Mildly Interesting @lemmy.world

    This German pub has a secure storage system for your personal tankards

  • What is this thing? @lemmy.world

    CHALLENGE: What is this thing?

  • New Communities @lemmy.world

    What is this thing?

    lemmy.world /c/whatisthisthing
  • What is this thing? @lemmy.world

    CHALLENGE: What is this thing?

  • Mildly Interesting @lemmy.world

    Sheep enjoying paddling in the river Rhine in Cologne