Day16: This should be faster ...
This commit is contained in:
parent
46b9098db9
commit
417c4ede04
24
day16.hs
24
day16.hs
|
@ -1,17 +1,12 @@
|
|||
import Data.Char
|
||||
import Debug.Trace as T
|
||||
|
||||
main = do
|
||||
cont <- getContents
|
||||
let content = (map digitToInt $ init cont)
|
||||
let base = [0,1,0,-1]
|
||||
let patter = drop 500 (map (getPatternForIndex base (length content)) [0..(length content)])
|
||||
let input = drop 500 content
|
||||
|
||||
let test1 = doSteps input patter 1
|
||||
--putStrLn (show input)
|
||||
let content = (drop 5977377 ( concat $ replicate 10000 (map digitToInt $ init cont) ))
|
||||
let test1 = doStepsP2 content 1
|
||||
putStrLn (show $ length content)
|
||||
--mapM putStrLn (map show patter)
|
||||
putStrLn (show test1)
|
||||
putStrLn (show $ test1)
|
||||
|
||||
getPatternForIndex :: [Int] -> Int -> Int -> [Int]
|
||||
getPatternForIndex patter length index = drop (1 + index) $ take (length +1) (cycle base)
|
||||
|
@ -31,3 +26,14 @@ doSteps :: [Int] -> [[Int]] -> Int -> [Int]
|
|||
doSteps xs patterns cnt
|
||||
| cnt == 0 = xs
|
||||
| otherwise = doSteps (step xs patterns) patterns (cnt -1)
|
||||
|
||||
|
||||
stepP2 :: [Int] -> Int -> [Int] -> [Int]
|
||||
stepP2 xs sumIn acc
|
||||
| sumIn == 0 = acc
|
||||
| sumIn > 0 = stepP2 (drop 1 xs) (sumIn - (head xs)) (acc ++ [mod sumIn 10])
|
||||
|
||||
doStepsP2 :: [Int] -> Int ->[Int]
|
||||
doStepsP2 xs cnt
|
||||
| cnt == 0 = xs
|
||||
| otherwise = doStepsP2 (stepP2 xs (sum(xs)) []) (cnt -1)
|
||||
|
|
Loading…
Reference in New Issue
Block a user