

0·
2 days agoOoh, 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

It’s gradually coming back to me. The Haskell Complex type doesn’t work particularly nicely as an integer, plus the definition of division is more like “scale”, so I just went with my own type.
Then I forgot which of
divandquotI should use, and kept getting nearly the right answer :/