A bit faster with Parallel, but still too slow
This commit is contained in:
parent
7c8cb639cb
commit
6ee8b3fafa
1 changed files with 10 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
#! /usr/bin/env -S"GHCRTS=-N4" nix-shell
|
#! /usr/bin/env -S"GHCRTS=-N4" nix-shell
|
||||||
#! nix-shell -p ghcid
|
#! nix-shell -p ghcid
|
||||||
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [pretty-simple attoparsec arithmoi containers])"
|
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [pretty-simple attoparsec arithmoi containers parallel])"
|
||||||
#! nix-shell -i "ghcid -c 'ghci' -T main"
|
#! nix-shell -i "ghcid -c 'ghci' -T main"
|
||||||
|
|
||||||
{-# OPTIONS_GHC -Wall -Wincomplete-uni-patterns #-}
|
{-# OPTIONS_GHC -Wall -Wincomplete-uni-patterns #-}
|
||||||
|
@ -27,6 +27,7 @@ import qualified Data.Attoparsec.Text as A
|
||||||
import qualified Data.IntSet as I
|
import qualified Data.IntSet as I
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
|
import Control.Parallel.Strategies (parMap, parListChunk, rdeepseq)
|
||||||
|
|
||||||
exampleData :: String
|
exampleData :: String
|
||||||
exampleData = "939\n7,13,x,x,59,x,31,19"
|
exampleData = "939\n7,13,x,x,59,x,31,19"
|
||||||
|
@ -98,7 +99,7 @@ isT tpx x xs = head $ catMaybes $ map go allTs
|
||||||
where
|
where
|
||||||
allTs = [158478605388*tpx,158478605389*tpx..]
|
allTs = [158478605388*tpx,158478605389*tpx..]
|
||||||
go :: Int -> Maybe Int
|
go :: Int -> Maybe Int
|
||||||
go tpx0 = case and (map (go' tpx0) xs) of
|
go tpx0 = case and (parMap rdeepseq (go' tpx0) xs) of
|
||||||
True -> Just (tpx0 - x)
|
True -> Just (tpx0 - x)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
go' tpx0' (shift,fact) =
|
go' tpx0' (shift,fact) =
|
||||||
|
@ -145,11 +146,11 @@ main = do
|
||||||
print $ 100000000000000 `mod` 631
|
print $ 100000000000000 `mod` 631
|
||||||
print $ 100000000000000 `div` 631
|
print $ 100000000000000 `div` 631
|
||||||
putStrLn ":: Day 13 - Part 2"
|
putStrLn ":: Day 13 - Part 2"
|
||||||
-- print $ solvePart2 "939\n3,5"
|
print $ solvePart2 "939\n3,5"
|
||||||
-- print $ solvePart2 exampleData
|
print $ solvePart2 exampleData
|
||||||
-- print $ solvePart2 "1\n17,x,13,19"
|
print $ solvePart2 "1\n17,x,13,19"
|
||||||
-- print $ solvePart2 "1\n67,7,59,61"
|
print $ solvePart2 "1\n67,7,59,61"
|
||||||
-- print $ solvePart2 "1\n67,x,7,59,61"
|
print $ solvePart2 "1\n67,x,7,59,61"
|
||||||
-- print $ solvePart2 "1\n67,7,x,59,61"
|
print $ solvePart2 "1\n67,7,x,59,61"
|
||||||
-- print $ solvePart2 "1\n1789,37,47,1889"
|
print $ solvePart2 "1\n1789,37,47,1889"
|
||||||
print $ solvePart2 input
|
print $ solvePart2 input
|
||||||
|
|
Loading…
Reference in a new issue