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:
6c33fcf
)
Got parallelism working on day 14
author
Neil Smith
<neil.git@njae.me.uk>
Sun, 18 Dec 2016 11:00:59 +0000
(11:00 +0000)
committer
Neil Smith
<neil.git@njae.me.uk>
Sun, 18 Dec 2016 11:00:59 +0000
(11:00 +0000)
advent14parallel.hs
patch
|
blob
|
history
diff --git
a/advent14parallel.hs
b/advent14parallel.hs
index cb3e1b648bed17373f8b863c4b8c08b05f3f72da..482b5e0cbc3cfffc66a63ac308b4ef29124cdc9f 100644
(file)
--- a/
advent14parallel.hs
+++ b/
advent14parallel.hs
@@
-1,11
+1,14
@@
import Data.List (nub, tails)
import Data.ByteString.Char8 (pack)
import Crypto.Hash (hash, Digest, MD5)
import Data.List (nub, tails)
import Data.ByteString.Char8 (pack)
import Crypto.Hash (hash, Digest, MD5)
-import Control.Parallel.Strategies (
parMap
, rdeepseq)
+import Control.Parallel.Strategies (
withStrategy, parBuffer
, rdeepseq)
salt = "yjdafjpo"
-- salt = "abc"
salt = "yjdafjpo"
-- salt = "abc"
+stretch_factor = [1..2016]
+-- stretch_factor = [1..100]
+
main :: IO ()
main = do
part1
main :: IO ()
main = do
part1
@@
-24,14
+27,14
@@
getHash bs = show (hash $ pack bs :: Digest MD5)
md5sequence :: [String]
-- md5sequence = [makeMd5 i | i <- [0..]]
md5sequence :: [String]
-- md5sequence = [makeMd5 i | i <- [0..]]
-md5sequence =
parMap rdeepseq
(makeMd5) [0..]
+md5sequence =
withStrategy (parBuffer 100 rdeepseq) $ map
(makeMd5) [0..]
where makeMd5 i = getHash (salt ++ show i)
md5sequenceS :: [String]
-- md5sequenceS = [makeMd5 i | i <- [0..]]
where makeMd5 i = getHash (salt ++ show i)
md5sequenceS :: [String]
-- md5sequenceS = [makeMd5 i | i <- [0..]]
-md5sequenceS =
parMap rdeepseq
(makeMd5) [0..]
+md5sequenceS =
withStrategy (parBuffer 100 rdeepseq) $ map
(makeMd5) [0..]
where makeMd5 i = stretch $ getHash (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
stretch_factor
possibleKey :: [String] -> Int-> Bool
possibleKey s = not . null . repeats 3 . ((!!) s)
possibleKey :: [String] -> Int-> Bool
possibleKey s = not . null . repeats 3 . ((!!) s)