Skip to content

Instantly share code, notes, and snippets.

@ar1a
Last active January 23, 2019 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ar1a/e9a4a0df7147e50d78041c38ed28526c to your computer and use it in GitHub Desktop.
Save ar1a/e9a4a0df7147e50d78041c38ed28526c to your computer and use it in GitHub Desktop.
aoc1 :: IO ()
aoc1 = do
-- part1 <- sum . getInput <$> getContents
part2 <- flip dupSum [] . getInput <$> getContents
print part2
pure ()
dupSum :: [Integer] -> [Integer] -> Integer
dupSum (x:xs) sofar =
let
newSum = sum (x:sofar)
in
if newSum `elem` sofar then
newSum
else
dupSum xs $ newSum:sofar
dupSum [] _ = error "oh no!" -- need to run dupSum initialInputs sofar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment