Day16: (++) has O(n)
This commit is contained in:
parent
417c4ede04
commit
196dbbff3e
10
day16.hs
10
day16.hs
|
@ -2,11 +2,11 @@ import Data.Char
|
||||||
|
|
||||||
main = do
|
main = do
|
||||||
cont <- getContents
|
cont <- getContents
|
||||||
let content = (drop 5977377 ( concat $ replicate 10000 (map digitToInt $ init cont) ))
|
let content = drop 5977377 (concat (replicate 10000 (map digitToInt $ init cont) ))
|
||||||
let test1 = doStepsP2 content 1
|
let test1 = doStepsP2 content 100
|
||||||
putStrLn (show $ length content)
|
putStrLn (show $ length content)
|
||||||
--mapM putStrLn (map show patter)
|
--mapM putStrLn (map show patter)
|
||||||
putStrLn (show $ test1)
|
putStrLn (show $ take 8 test1)
|
||||||
|
|
||||||
getPatternForIndex :: [Int] -> Int -> Int -> [Int]
|
getPatternForIndex :: [Int] -> Int -> Int -> [Int]
|
||||||
getPatternForIndex patter length index = drop (1 + index) $ take (length +1) (cycle base)
|
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 :: [Int] -> Int -> [Int] -> [Int]
|
||||||
stepP2 xs sumIn acc
|
stepP2 xs sumIn acc
|
||||||
| sumIn == 0 = acc
|
| sumIn == 0 = reverse acc
|
||||||
| sumIn > 0 = stepP2 (drop 1 xs) (sumIn - (head xs)) (acc ++ [mod sumIn 10])
|
| sumIn > 0 = stepP2 (drop 1 xs) (sumIn - (head xs)) ((mod sumIn 10):acc)
|
||||||
|
|
||||||
doStepsP2 :: [Int] -> Int ->[Int]
|
doStepsP2 :: [Int] -> Int ->[Int]
|
||||||
doStepsP2 xs cnt
|
doStepsP2 xs cnt
|
||||||
|
|
Loading…
Reference in New Issue
Block a user