Day16: (++) has O(n)

This commit is contained in:
Arranun 2019-12-16 21:16:22 +01:00
parent 417c4ede04
commit 196dbbff3e

View File

@ -2,11 +2,11 @@ import Data.Char
main = do
cont <- getContents
let content = (drop 5977377 ( concat $ replicate 10000 (map digitToInt $ init cont) ))
let test1 = doStepsP2 content 1
let content = drop 5977377 (concat (replicate 10000 (map digitToInt $ init cont) ))
let test1 = doStepsP2 content 100
putStrLn (show $ length content)
--mapM putStrLn (map show patter)
putStrLn (show $ test1)
putStrLn (show $ take 8 test1)
getPatternForIndex :: [Int] -> Int -> Int -> [Int]
getPatternForIndex patter length index = drop (1 + index) $ take (length +1) (cycle base)
@ -30,8 +30,8 @@ doSteps xs patterns cnt
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])
| sumIn == 0 = reverse acc
| sumIn > 0 = stepP2 (drop 1 xs) (sumIn - (head xs)) ((mod sumIn 10):acc)
doStepsP2 :: [Int] -> Int ->[Int]
doStepsP2 xs cnt