projects
/
advent-of-code-16.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3fef2ec
)
Tidying
author
Neil Smith
<neil.git@njae.me.uk>
Wed, 14 Dec 2016 19:48:34 +0000
(19:48 +0000)
committer
Neil Smith
<neil.git@njae.me.uk>
Wed, 14 Dec 2016 19:48:34 +0000
(19:48 +0000)
advent14.hs
patch
|
blob
|
history
advent14c.hs
patch
|
blob
|
history
diff --git
a/advent14.hs
b/advent14.hs
index f48dc6f55335d308e992cf60b54b8ceb35fd3279..22491ddf7f8a7626241882622ecaffb13b440d34 100644
(file)
--- a/
advent14.hs
+++ b/
advent14.hs
@@
-10,11
+10,11
@@
main = do
part2
part1 :: IO ()
part2
part1 :: IO ()
-part1 = print $ head $ drop 63 $ filter (\i -> possible
Start sq i && confirmStart
sq i) [0..]
+part1 = print $ head $ drop 63 $ filter (\i -> possible
Key sq i && confirmKey
sq i) [0..]
where sq = md5sequence
part2 :: IO ()
where sq = md5sequence
part2 :: IO ()
-part2 = print $ head $ drop 63 $ filter (\i -> possible
Start sq i && confirmStart
sq i) [0..]
+part2 = print $ head $ drop 63 $ filter (\i -> possible
Key sq i && confirmKey
sq i) [0..]
where sq = md5sequenceS
md5sequence :: [String]
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]
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)
-confirm
Start
:: [String] -> Int -> Bool
-confirm
Start
s i = any (confirmation) $ take 1000 $ drop (i+1) s
+confirm
Key
:: [String] -> Int -> Bool
+confirm
Key
s i = any (confirmation) $ take 1000 $ drop (i+1) s
where c = head $ repeats 3 $ s!!i
confirmation m = c `elem` (repeats 5 m)
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
substrings :: Int -> [a] -> [[a]]
substrings l = filter (\s -> (length s) == l) . map (take l) . tails
-
diff --git
a/advent14c.hs
b/advent14c.hs
index 8f1eb6b506c58dbbd280f270b410a6a9850bfb3b..a43e37fe4233d0a13ae4c9446fcc0cdaf966ed27 100644
(file)
--- a/
advent14c.hs
+++ b/
advent14c.hs
@@
-1,6
+1,4
@@
-import Data.List (nub, tails, null)
-import Data.Hash.MD5 (md5s, Str(..))
-
+import Data.List (nub, tails)
import Data.ByteString.Char8 (pack)
import Crypto.Hash (hash, Digest, MD5)
import Data.ByteString.Char8 (pack)
import Crypto.Hash (hash, Digest, MD5)
@@
-12,16
+10,14
@@
main = do
part1
part2
part1
part2
-
part1 :: IO ()
part1 :: IO ()
-part1 = print $ head $ drop 63 $ filter (\i -> possible
Start sq i && confirmStart
sq i) [0..]
+part1 = print $ head $ drop 63 $ filter (\i -> possible
Key sq i && confirmKey
sq i) [0..]
where sq = md5sequence
part2 :: IO ()
where sq = md5sequence
part2 :: IO ()
-part2 = print $ head $ drop 63 $ filter (\i -> possible
Start sq i && confirmStart
sq i) [0..]
+part2 = print $ head $ drop 63 $ filter (\i -> possible
Key sq i && confirmKey
sq i) [0..]
where sq = md5sequenceS
where sq = md5sequenceS
-
getHash :: String -> String
getHash bs = show (hash $ pack bs :: Digest MD5)
getHash :: String -> String
getHash bs = show (hash $ pack bs :: Digest MD5)
@@
-31,19
+27,17
@@
md5sequence = [makeMd5 i | i <- [0..]]
md5sequenceS :: [String]
md5sequenceS = [makeMd5 i | i <- [0..]]
md5sequenceS :: [String]
md5sequenceS = [makeMd5 i | i <- [0..]]
- where makeMd5 i = stretch $
md5s (Str (salt ++ show i))
+ where makeMd5 i = stretch $
getHash (salt ++ show i)
stretch h0 = foldr (\_ h -> getHash h) h0 [1..2016]
stretch h0 = foldr (\_ h -> getHash 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)
-confirm
Start
:: [String] -> Int -> Bool
-confirm
Start
s i = any (confirmation) $ take 1000 $ drop (i+1) s
+confirm
Key
:: [String] -> Int -> Bool
+confirm
Key
s i = any (confirmation) $ take 1000 $ drop (i+1) s
where c = head $ repeats 3 $ s!!i
confirmation m = c `elem` (repeats 5 m)
where c = head $ repeats 3 $ s!!i
confirmation m = c `elem` (repeats 5 m)
-
repeats :: Int -> String -> [String]
repeats n = filter (null . tail) . map (nub) . substrings n
repeats :: Int -> String -> [String]
repeats n = filter (null . tail) . map (nub) . substrings n