this post was submitted on 08 Dec 2025
21 points (100.0% liked)

Advent Of Code

1199 readers
3 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 2025

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

Day 8: Playground

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
[–] lwhjp@piefed.blahaj.zone 5 points 2 weeks ago* (last edited 2 weeks ago) (1 children)

Haskell

They're getting interesting now!

import Control.Monad  
import Data.List  
import Data.List.Split  
import Data.Ord  
import Data.Set qualified as Set  

readPos = (\([x, y, z] :: [Int]) -> (x, y, z)) . map read . splitOn ","  

pairs = init . tails >=> (\(x : xs) -> map (x,) xs)  

dist (x1, y1, z1) (x2, y2, z2) =  
  (x2 - x1) ^ 2 + (y2 - y1) ^ 2 + (z2 - z1) ^ 2  

connect circuits (a, b) =  
  let (joined, rest) =  
        partition (\c -> a `Set.member` c || b `Set.member` c) circuits  
   in Set.unions joined : rest  

main = do  
  boxes <- map readPos . lines <$> readFile "input08"  
  let steps =  
        (zip <*> tail . scanl' connect (map Set.singleton boxes)) $  
          sortOn (uncurry dist) (pairs boxes)  
  print . product . take 3 . sortOn Down . map Set.size $  
    (snd . last . take 1000 $ steps)  
  let Just (((x1, _, _), (x2, _, _)), _) =  
        find ((== 1) . length . snd) steps  
   in print $ x1 * x2  
[–] VegOwOtenks@lemmy.world 2 points 2 weeks ago (1 children)

This is crazy concise and fast! Impressive.

[–] lwhjp@piefed.blahaj.zone 2 points 2 weeks ago

Thank you! ☺️