this post was submitted on 05 Nov 2025
11 points (92.3% liked)

Advent Of Code

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

Quest 1: Whispers in the Shell

  • 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

Link to participate: https://everybody.codes/

you are viewing a single comment's thread
view the rest of the comments
[โ€“] lwhjp@piefed.blahaj.zone 4 points 4 days ago* (last edited 4 days ago) (1 children)

Ooh, challenges! Here we go!

I haven't really written any Haskell since last year's AoC, and boy am I rusty.

import Control.Monad  
import Data.List  
import Data.List.Split  
import Data.Vector qualified as V  

readInput s =  
  let [names, _, moves] = splitOn "," <$> lines s  
   in (names, map readMove moves)  
  where  
    readMove (d : s) =  
      let n = read s :: Int  
       in case d of  
            'L' -> -n  
            'R' -> n  

addWith f = (f .) . (+)  

part1 names moves =  
  names !! foldl' (addWith $ clamp (length names)) 0 moves  
  where  
    clamp n x  
      | x < 0 = 0  
      | x >= n = n - 1  
      | otherwise = x  

part2 names moves =  names !! (sum moves `mod` length names)  

part3 names moves =  
  V.head  
    . foldl' exchange (V.fromList names)  
    $ map (`mod` length names) moves  
  where  
    exchange v k = v V.// [(0, v V.! k), (k, V.head v)]  

main =  
  forM_  
    [ ("everybody_codes_e2025_q01_p1.txt", part1),  
      ("everybody_codes_e2025_q01_p2.txt", part2),  
      ("everybody_codes_e2025_q01_p3.txt", part3)  
    ]  
    $ \(input, solve) ->  
      readFile input >>= putStrLn . uncurry solve . readInput  
[โ€“] ragingHungryPanda@piefed.keyboardvagabond.com 2 points 4 days ago (1 children)

What do the .s mean in addWith f = (f .) . (+)?

[โ€“] Noughtmare@programming.dev 3 points 3 days ago* (last edited 3 days ago)

. means function composition in Haskell. (f .) . (+) is just an obscure way to write \x y -> f (x + y). It's not recommended to use this point-free style in production code, but it is sometimes fun to experiment with for challenges like this.