1 import qualified Data.Set as S
4 contents <- getContents
5 let freqs = cycle $ map toInt (lines contents)
6 print $ findDouble (S.empty :: S.Set Int) 0 freqs
9 toInt (x:xs) = if x == '+'
11 else -(read xs :: Int)
13 findDouble :: S.Set Int -> Int -> [Int] -> Int
14 findDouble history total (x:xs)
15 | S.member total history = total
16 | otherwise = findDouble nextHist nextTotal xs
17 where nextHist = S.insert total history