Created
December 1, 2018 15:39
-
-
Save pete-murphy/e55228d0d590f01da811c2cb4648143b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
removePlus :: String -> String | |
removePlus = filter (/= '+') | |
toInts :: String -> [Int] | |
toInts = map ((read :: String -> Int) . removePlus) . lines | |
solve :: [Int] -> Int | |
solve xs = go [0] xs | |
where | |
go acc [] = go acc xs | |
go acc@(a:_) (y:ys) = | |
if elem (y + a) acc | |
then (y + a) | |
else go ((y + a) : acc) ys | |
main :: IO () | |
main = do | |
text <- readFile "input.txt" | |
putStrLn $ show $ solve $ toInts text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment