23

Day 3: Foggy Forest

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
[-] mykl@lemmy.world 6 points 1 day ago* (last edited 1 day ago)

Uiua

Really just brute force, ~~but it only takes a few seconds~~ (see below). Looking forward to seeing what I missed. [Edit: Tidied up logic.]

"#.###\n.##.#\n##.##\n.#.#.\n.##.#"
β§…<2⊚=@#βŠœβˆ˜βŠΈβ‰ @\n
M  ← /+∊+βŠΈβ‰‘(€×1_Β―1β‡ŒβŠΈ/-) # Does edge have matching edge?
P₁ ← M β–½=1βŠΈβ‰‘(β§»β—΄βŠ’β‰)      # Only pick horz. edges.
Pβ‚‚ ← Γ·2M                # All edges, div by two as both slopes will be found.
βŠƒP₁ Pβ‚‚

I know no-one cares apart from me now, but inspired by some discussion on the Uiua discord, I used complex numbers to simplify calculating the opposite edges, and got rid of expensive rows operations, at the expense of some slightly more convoluted code. But! the following now solves with live data in <0.2 seconds native, 0.4 in Uiua Pad. Marked Experimental as subscripted transform is still bleeding edge.

# Experimental!
"#.###\n.##.#\n##.##\n.#.#.\n.##.#" # Replace with live data :-)
β§…β‚‚<⊸⊚=@#βŠœβˆ˜βŠΈβ‰ @\n                     # Find trees, keep and pair up.
M  ← /+/Γ—β‰βœβ™­β‚‚β¬š0⊑+β‰‘Β€β‰βœ(β„‚Β°βŠŸ|Γ—i)/-βŠΈβ‰   # For every edge, find lower edge, check both points have trees.
P₁ ← M β–½=0βŠ’β‰/-βŠΈβ‰β‚‚                   # Filter pairs on same row (i.e. top edges)
Pβ‚‚ ← Γ·β‚‚M                            # All edges, div by 2 as both slopes will be found.
&p ⍜now(βŠƒP₁ Pβ‚‚)

Try it here!

this post was submitted on 03 Dec 2026
23 points (100.0% liked)

Advent Of Code

1278 readers
56 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 2026

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 3 years ago
MODERATORS