Skip to content

Instantly share code, notes, and snippets.

@pete-murphy
Created December 1, 2018 15:39
Show Gist options
  • Save pete-murphy/e55228d0d590f01da811c2cb4648143b to your computer and use it in GitHub Desktop.
Save pete-murphy/e55228d0d590f01da811c2cb4648143b to your computer and use it in GitHub Desktop.
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