this post was submitted on 04 Dec 2024
18 points (95.0% liked)

Advent Of Code

987 readers
14 users here now

An unofficial home for the advent of code community on programming.dev!

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.

AoC 2024

Solution Threads

M T W T F S S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25

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 1 year ago
MODERATORS
 

Day 4: Ceres Search

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 4 points 3 weeks ago* (last edited 3 weeks ago) (1 children)

Uiua

Just part1 for now as I need to walk the dog :-)

[edit] Part 2 now added, and a nicer approach than Part 1 in my opinion, if you're able to keep that many dimensions straight in your head :-)

[edit 2] Tightened it up a bit more.

Grid ← ⊜∘⊸≠@\n "MMMSXXMASM\nMSAMXMSMSA\nAMXSXMAAMM\nMSAMASMSMX\nXMASAMXAMM\nXXAMMXXAMA\nSMSMSASXSS\nSAXAMASAAA\nMAMMMXMMMM\nMXMXAXMASX"

≡⍉⍉×⇡4¤[1_0 0_1 1_1 1_¯1]         # Use core dirs to build sets of 4-offsets.
↯∞_2⇡△ Grid                       # Get all possible starting points.
&p/+♭⊞(+∩(≍"XMAS")⇌.⬚@.⊡:Grid≡+¤) # Part 1. Join the two into a table, use to pick 4-elements, check, count.

Diags   ← [[¯. 1_1] [¯. 1_¯1]]
BothMas ← /×≡(+∩(≍"MS")⇌.)⬚@.⊡≡+Diags¤¤ # True if both diags here are MAS.
&p/+≡BothMas⊚="A"⟜¤Grid                 # Part 2. For all "A"s in grid, check diags, count where good.
[–] urquell@lemm.ee 3 points 3 weeks ago (1 children)

I'm not even sure how to write most of these characters

[–] mykl@lemmy.world 2 points 3 weeks ago (1 children)

The operators have all got ascii names you can type, and the formatter converts them to the symbols. It's a bit odd but really worthwhile, as you get access to the powerful array handling functionality that made solving today's challenges so much more straightforward than in other languages.

[–] urquell@lemm.ee 2 points 3 weeks ago

It looks quite functional indeed