From 9d534067ab1ad76f9cb8110f9566b03dd6f15e6f Mon Sep 17 00:00:00 2001 From: Abhinav Sarkar Date: Sat, 1 Dec 2018 19:57:33 +0530 Subject: [PATCH] Adds solution 1 --- .gitignore | 31 +++++++++++++++++++++++++++++++ 1/1.hs | 17 +++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .gitignore create mode 100644 1/1.hs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4e50e09 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ + +# Created by https://www.gitignore.io/api/haskell +# Edit at https://www.gitignore.io/?templates=haskell + +### Haskell ### +dist +dist-* +cabal-dev +*.o +*.hi +*.chi +*.chs.h +*.dyn_o +*.dyn_hi +.hpc +.hsenv +.cabal-sandbox/ +cabal.sandbox.config +*.prof +*.aux +*.hp +*.eventlog +.stack-work/ +cabal.project.local +cabal.project.local~ +.HTF/ +.ghc.environment.* + +# End of https://www.gitignore.io/api/haskell + +*/input diff --git a/1/1.hs b/1/1.hs new file mode 100644 index 0000000..c0b96e9 --- /dev/null +++ b/1/1.hs @@ -0,0 +1,17 @@ +module Main where + +import qualified Data.IntSet as Set + +main = do + changes <- map (read . dropPlus) . lines <$> getContents + let sums = scanl (+) 0 . cycle $ changes + putStrLn $ show $ sum changes + putStrLn $ show $ firstDup sums + +dropPlus ('+':cs) = cs +dropPlus cs = cs + +firstDup :: [Int] -> Int +firstDup = go Set.empty + where + go seen (x:xs) = if x `Set.member` seen then x else go (Set.insert x seen) xs