summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaura Orvokki Kursula <lav@vampires.gay>2024-12-03 22:06:45 +0100
committerLaura Orvokki Kursula <lav@vampires.gay>2024-12-03 22:06:45 +0100
commit1f6080dfae0b1ff748790f8b6afda15cab3117aa (patch)
treef217e0a51b913b950f9e436df437a72d215910f9
parent818e93ec4aa870d020be71981d4c2d1d72390ed2 (diff)
downloadaoc2024-1f6080dfae0b1ff748790f8b6afda15cab3117aa.tar.gz
aoc2024-1f6080dfae0b1ff748790f8b6afda15cab3117aa.zip
1-2
-rw-r--r--1-2.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/1-2.hs b/1-2.hs
new file mode 100644
index 0000000..3fc718e
--- /dev/null
+++ b/1-2.hs
@@ -0,0 +1,14 @@
+count :: Eq a => a -> [a] -> Int
+count x = foldr f 0
+ where
+ f y n | x == y = n + 1
+ | otherwise = n
+
+main :: IO ()
+main = do
+ ls <- getContents
+ let ns = map (map read . words) . lines $ ls
+ let xs = map head ns
+ let ys = map last ns
+ let ms = map (\x -> x * count x ys) xs
+ print (sum ms)