never executed always true always false
1 {-|
2 Module: Y2015.D04
3 Description: Advent of Code Day 04 Solutions.
4 License: MIT
5 Maintainer: @tylerjl
6
7 Solutions to the day 04 set of problems for <adventofcode.com>.
8 -}
9 module Y2015.D04
10 ( crack
11 ) where
12
13 import Crypto.Hash.MD5 (hash)
14 import Data.ByteString.Base16 (encode)
15 import qualified Data.ByteString.Char8 as C
16
17 -- |Cracks password hash to retrieve original value
18 crack
19 :: C.ByteString -- ^ Input hash
20 -> Int -- ^ Number of leading zeroes
21 -> Int -- ^ Original password value
22 crack prefix d = head $ dropWhile (not . validSuffix) [0 ..]
23 where
24 validSuffix = check . encode . hash . (prefix <>) . C.pack . show
25 check = (>= d) . C.length . C.takeWhile (== '0')