From 1f6080dfae0b1ff748790f8b6afda15cab3117aa Mon Sep 17 00:00:00 2001 From: Laura Orvokki Kursula Date: Tue, 3 Dec 2024 22:06:45 +0100 Subject: 1-2 --- 1-2.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 1-2.hs 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) -- cgit v1.2.3