Skip to content

Instantly share code, notes, and snippets.

@travisby
Created December 5, 2015 16:25
Show Gist options
  • Save travisby/508058db33c5fd9626a4 to your computer and use it in GitHub Desktop.
Save travisby/508058db33c5fd9626a4 to your computer and use it in GitHub Desktop.
advent_day_04.hs
module Main where
import Data.Hash.MD5
main = do
input <- getContents
let key = init input
let firstResult = head . filter (isAdventCoin key 5) $ [1..]
putStr "00000...: "
print firstResult
putStr "000000...: "
print . head . filter (isAdventCoin key 6) $ [firstResult..]
isAdventCoin :: String -> Int -> Int -> Bool
isAdventCoin key size x = take size (md5s $ Str $ key ++ show x) == replicate size '0'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment