Move day1 to its own folder
This commit is contained in:
parent
2be3c1f086
commit
68b10c50b1
2 changed files with 0 additions and 22 deletions
8
Day1A.hs
8
Day1A.hs
|
@ -1,8 +0,0 @@
|
|||
module Day1A where
|
||||
|
||||
read' :: String -> Int
|
||||
read' ('+':str) = read str
|
||||
read' str = read str
|
||||
|
||||
main :: IO ()
|
||||
main = interact $ show . sum . map read' . lines
|
14
Day1B.hs
14
Day1B.hs
|
@ -1,14 +0,0 @@
|
|||
module Day1B where
|
||||
|
||||
import Day1A (read')
|
||||
import qualified Data.IntSet as S
|
||||
|
||||
handle :: Int -> S.IntSet -> [Int] -> Int
|
||||
handle freq history (nextDelta:xs)
|
||||
| S.member freq history = freq -- When the frequency is in the history set, return it
|
||||
| otherwise = handle (freq + nextDelta) (S.insert freq history) xs -- Recurse otherwise
|
||||
handle _ _ _ = error "xs should not be empty :("
|
||||
|
||||
main :: IO ()
|
||||
main = interact $ show . handle 0 S.empty . deltaFreqs
|
||||
where deltaFreqs = cycle . map read' . lines -- Convert input to Ints and repeat infinitely
|
Loading…
Reference in a new issue