PostsBlogReposAbout
Samuel1 Dec 2024
I just completed "Historian Hysteria" - Day 1 - Advent of Code 2024 #AdventOfCode adventofcode.com/2024/day/1
5 2 120
Samuel
@samuel.fm
haskell spoilers
Adult content
import Data.List

main :: IO ()
main = do
  input <- readFile "input.txt"
  let (left, right) = listPairsToPairList $ map words (lines input)
  print $ sum $ distPairs (sort left, sort right)

listPairsToPairList :: [[String]] -> ([Int], [Int])
listPairsToPairList xs = (map (read . head) xs, map (read . last) xs)

distPairs :: ([Int], [Int]) -> [Int]
distPairs ([], []) = []
distPairs (x:xs, y:ys) = abs (x - y) : distPairs (xs, ys)
main :: IO ()
main = do
  input <- readFile "input.txt"
  let (left, right) = listPairsToPairList $ map words (lines input)
  print $ sumSimScore left right


listPairsToPairList :: [[String]] -> ([Int], [Int])
listPairsToPairList [] = ([], [])
listPairsToPairList xs = (map (read . head) xs, map (read . last) xs)

simScore :: Int -> [Int] -> Int
simScore _ [] = 0
simScore x (y:ys)
  | x == y = x + simScore x ys
  | otherwise = simScore x ys

sumSimScore :: [Int] -> [Int] -> Int
sumSimScore [] _ = 0
sumSimScore (x:xs) ys = simScore x ys + sumSimScore xs ys
5 3 30
1 December 2024 at 2:03 pmView on Bluesky
Samuel1 Dec 2024
beautiful language :)
9
David Buchanan1 Dec 2024
well that isn't very pythonic
1 9
Samuel1 Dec 2024
correct it's haskellic
8
mary🐇1 Dec 2024
we need dedicated spoiler label so bad i cant believe we're tagging programming as adult content
2 1 22
Samuel1 Dec 2024
no child should be exposed to Haskell
1 24
Bohdan Pavuk1 Dec 2024
true, same can be said about C. trust me, I'm 16 and I know what I'm talking about
1 5
Ricardo J. Méndez1 Dec 2024
It depends on what your fetish is.
1
neuro2 Dec 2024
haskell is the reason i quit my cs degree at glasgow uni
mussar1 Dec 2024
haskell looks so cozy