mykl

u/mykl@lemmy.world
71 posts · 512 comments

Recent posts

Recent comments

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")

Uiua

If it's stupid but it works...

::: spoiler My dirty hack 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₂

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:

::: spoiler How to solve part 2 without libraries 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...

::: spoiler a hint that might help you 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.

on line noise · c/programmer_humor · 3 pts · 251d

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

::: spoiler 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.

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

::: spoiler 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/+≡◇⧻)

⊃(&p⍜nowPart₁)(&p⍜nowPart₂) &p⍜now(IndexPrep Sort Parse)

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

Uiua

Messy code that might be worth revisiting later, but array handling is right up Uiua's street.

# AOC 2025 Day 6
D     ← "123 328  51 64 \n 45 64  387 23 \n  6 98  215 314\n*   +   *   +  "
# D     ← &fras"AOC2025day06.txt"
Parse ← ⊃↘↙¯1⊜∘⊸≠@\n
P₁ ← (
  ⊃⋅∘∘⍉⊓◇⋕⊢∩≡(⊜□⊸≠@\s)⊃↘↙¯1⊜∘⊸≠@\nD
  /+≡◇(⨬(/+|/×)≍"*")≡°□
)

P₂ ← (
  ⍉
  ⬚@\s⊜∘⊸(≡/↥∊"0123456789")
  ⊜∘⊸≠@\s⊃⋅∘∘≡₁(⬚∞⋕▽⊸≠@\s)
  /+≡◇(⨬(/+⍜⊏⋅0⊚⊸=∞|/×⍜⊏⋅1⊚⊸=∞)≍"*")
)
⊂ P₁ P₂ Parse D