Browse Source

Adds solution 1

Abhinav Sarkar 2 years ago
commit
9d534067ab
2 changed files with 48 additions and 0 deletions
  1. 31
    0
      .gitignore
  2. 17
    0
      1/1.hs

+ 31
- 0
.gitignore View File

@@ -0,0 +1,31 @@
1
+
2
+# Created by https://www.gitignore.io/api/haskell
3
+# Edit at https://www.gitignore.io/?templates=haskell
4
+
5
+### Haskell ###
6
+dist
7
+dist-*
8
+cabal-dev
9
+*.o
10
+*.hi
11
+*.chi
12
+*.chs.h
13
+*.dyn_o
14
+*.dyn_hi
15
+.hpc
16
+.hsenv
17
+.cabal-sandbox/
18
+cabal.sandbox.config
19
+*.prof
20
+*.aux
21
+*.hp
22
+*.eventlog
23
+.stack-work/
24
+cabal.project.local
25
+cabal.project.local~
26
+.HTF/
27
+.ghc.environment.*
28
+
29
+# End of https://www.gitignore.io/api/haskell
30
+
31
+*/input

+ 17
- 0
1/1.hs View File

@@ -0,0 +1,17 @@
1
+module Main where
2
+
3
+import qualified Data.IntSet as Set
4
+
5
+main = do
6
+  changes <- map (read . dropPlus) . lines <$> getContents
7
+  let sums = scanl (+) 0 . cycle $ changes
8
+  putStrLn $ show $ sum changes
9
+  putStrLn $ show $ firstDup sums
10
+
11
+dropPlus ('+':cs) = cs
12
+dropPlus cs = cs
13
+
14
+firstDup :: [Int] -> Int
15
+firstDup = go Set.empty
16
+  where
17
+    go seen (x:xs) = if x `Set.member` seen then x else go (Set.insert x seen) xs

Loading…
Cancel
Save