2
u/drislands 1d ago
This is the first time in a long time I've tried the AoC...and the first time since I started learning Haskell! Posted my solution to my profile.
1
u/vitelaSensei 1d ago
This year I'm doing a prelude-only version where I need to reinvent the wheel along the way. Today only required re-writing `sort` and `Data.Ord (Down)`
2
u/AustinVelonaut 1d ago
Fun project to implement (and understand) various data structures and functions. Do you build up a local library of them for the year that you can reuse for later puzzles, or is each day a "start from scratch" day?
1
u/vitelaSensei 1d ago
I'm gonna build my own base package every day bit by bit to reuse it. Otherwise I'm gonna end up with 10 implementations of a Map :p
Then when I reuse something I'll link to the post where it was implemented
1
u/mstksg 1d ago
Wow am I washed :) Some silly mistakes I made:
Parsed as
Doubleinstead ofInteven though Double never shows up in Advent of Code.Calculated the sum of the first three frequencies instead of the product
Found the product of the three least common instead of the three most common.
All of these silly mistakes motivate me to get back in practice haha. The struggle is real.
Anyway in Haskell this is pretty simple, it reads the same in bash or any other text processing language probably. Parsing is lines, and you can find the freq list using Data.Map.fromListWith (+). And the difference between Part 1 and Part 2 is just the order that you sort the frequencies before you sum them.
import Data.Map qualified as M
-- | List of codes and their frequencies
freqList :: String -> [(String, Int)]
freqList = M.toList . M.fromListWith (+) . map (,1) . lines
part1 :: String -> Int
part1 = product . map (read . fst) . take 3 . sortOn (Down . snd) . freqList
part2 :: String -> Int
part2 = product . map (read . fst) . take 3 . sortOn snd . freqListhttps://github.com/mstksg/advent-of-code/wiki/Reflections-2026
1
u/ChavXO 17h ago
Using GHCi and dataframes.
ghci> df <- D.readCsvWithOpts (defaultReadOptions { D.headerSpec = D.NoHeader }) "../../aoc/01/input.txt"
ghci> df |> D.groupBy ["0"] |> D.aggregate ["total" .= F.countAll] |> D.sortBy [D.Desc (D.int "total")] |> D.take 3 |> D.columnAsList (D.int "0") |> product
ghci> df |> D.groupBy ["0"] |> D.aggregate ["total" .= F.countAll] |> D.sortBy [D.Asc (D.int "total")] |> D.take 3 |> D.columnAsList (D.int "0") |> product
5
u/sondr3_ 1d ago
This year I'm branching out and I'm trying Roc after using Haskell the last ~six years after seeing the 0.1 release pop up on HN. My solution for today is quite Haskelly, but I'm definitely missing a few things from the Haskell ecosystem and I'm still not quite sure I like how magic creating types is (though it gives me PureScript vibes with row polymorphism). I'll refrain from posting in the other daily threads unless people are curious.