Created
December 5, 2015 16:25
-
-
Save travisby/508058db33c5fd9626a4 to your computer and use it in GitHub Desktop.
advent_day_04.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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