Abhinav Sarkar 2018-12-01 19:57:33 +05:30
коміт 9d534067ab
2 змінених файлів з 48 додано та 0 видалено

31
.gitignore сторонній Normal file

@ -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

17
1/1.hs Normal file

@ -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