Adds solution 1
This commit is contained in:
commit
9d534067ab
31
.gitignore
vendored
Normal file
31
.gitignore
vendored
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
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
|
Loading…
Reference in New Issue
Block a user