diff options
author | Laura Orvokki Kursula <lav@vampires.gay> | 2024-12-07 13:04:59 +0100 |
---|---|---|
committer | Laura Orvokki Kursula <lav@vampires.gay> | 2024-12-07 13:04:59 +0100 |
commit | f6bd85a982cd057cd9c7f573686e50c5d8680b0f (patch) | |
tree | 1983c08a122f37358f7986d6cdd5728e6c84a63a | |
parent | 1c166e353d82643b70d87044e300a1a6237cf9a8 (diff) | |
download | aoc2024-f6bd85a982cd057cd9c7f573686e50c5d8680b0f.tar.gz aoc2024-f6bd85a982cd057cd9c7f573686e50c5d8680b0f.zip |
7-1
-rw-r--r-- | 7-1.hs | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -0,0 +1,22 @@ +combine :: [Int] -> [Int] +combine (x:xs) = foldl f [x] xs + where + f :: [Int] -> Int -> [Int] + f ns n = [(+), (*)] <*> ns <*> [n] + +check :: Int -> [Int] -> Bool +check x xs = elem x (combine xs) + +parseLine :: String -> (Int,[Int]) +parseLine s = (read $ init x, map read xs) + where + (x:xs) = words s + +result :: [(Int,[Int])] -> Int +result xs = sum . map fst . filter snd + $ zip (map fst xs) (map (uncurry check) xs) + +main :: IO () +main = do + ls <- lines <$> getContents + print . result . map parseLine $ ls |