Tidying
[advent-of-code-16.git] / advent14.hs
index f48dc6f55335d308e992cf60b54b8ceb35fd3279..22491ddf7f8a7626241882622ecaffb13b440d34 100644 (file)
@@ -10,11 +10,11 @@ main = do
         part2
 
 part1 :: IO ()
-part1 = print $ head $ drop 63 $ filter (\i -> possibleStart sq i && confirmStart sq i) [0..]
+part1 = print $ head $ drop 63 $ filter (\i -> possibleKey sq i && confirmKey sq i) [0..]
     where sq = md5sequence
 
 part2 :: IO ()
-part2 = print $ head $ drop 63 $ filter (\i -> possibleStart sq i && confirmStart sq i) [0..]
+part2 = print $ head $ drop 63 $ filter (\i -> possibleKey sq i && confirmKey sq i) [0..]
     where sq = md5sequenceS
 
 md5sequence :: [String]
@@ -26,12 +26,11 @@ md5sequenceS = [makeMd5 i | i <- [0..]]
     where makeMd5 i = stretch $ md5s (Str (salt ++ show i)) 
           stretch h0 = foldr (\_ h -> md5s (Str h)) h0 [1..2016]
 
-possibleStart :: [String] -> Int-> Bool
--- possibleStart s i = not $ null $ repeats 3 $ s!!i
-possibleStart s = not . null . repeats 3 . ((!!) s)
+possibleKey :: [String] -> Int-> Bool
+possibleKey s = not . null . repeats 3 . ((!!) s)
 
-confirmStart :: [String] -> Int -> Bool
-confirmStart s i = any (confirmation) $ take 1000 $ drop (i+1) s
+confirmKey :: [String] -> Int -> Bool
+confirmKey s i = any (confirmation) $ take 1000 $ drop (i+1) s
     where c = head $ repeats 3 $ s!!i
           confirmation m = c `elem` (repeats 5 m)
 
@@ -40,4 +39,3 @@ repeats n = filter (null . tail) . map (nub) . substrings n
 
 substrings :: Int -> [a] -> [[a]]
 substrings l = filter (\s -> (length s) == l) . map (take l) . tails
-