Day16: Half needed time by ignoring multiplication with 0
This commit is contained in:
parent
5a307bfa6e
commit
17ef30b293
14
day16.hs
14
day16.hs
|
@ -4,21 +4,25 @@ main = do
|
|||
content <- getContents
|
||||
let input = map digitToInt $ init content
|
||||
let base = [0,1,0,-1]
|
||||
let patter = map (getPatternForIndex base (length input)) [1..(length input)]
|
||||
let patter = map (getPatternForIndex base (length input)) [0..(length input)]
|
||||
let test1 = doSteps input patter 100
|
||||
putStrLn (show input)
|
||||
--putStrLn (show input)
|
||||
--mapM putStrLn (map show patter)
|
||||
putStrLn (show test1)
|
||||
|
||||
getPatternForIndex :: [Int] -> Int -> Int -> [Int]
|
||||
getPatternForIndex patter length index = drop 1 $ take (length +1) (cycle base)
|
||||
where base = concat $ map (replicate index) patter
|
||||
getPatternForIndex patter length index = drop (1 + index) $ take (length +1) (cycle base)
|
||||
where base = concat $ map (replicate (index+1)) patter
|
||||
|
||||
getInputForIndex :: [Int] -> Int -> [Int]
|
||||
getInputForIndex xs index = drop index xs
|
||||
|
||||
get :: [Int] -> Int
|
||||
get xs = mod (abs $ (sum xs)) 10
|
||||
|
||||
step :: [Int] -> [[Int]] -> [Int]
|
||||
step xs patterns = map ( get . zipWith (*) xs ) patterns
|
||||
step xs patterns = map (\(a,b) -> get( zipWith (*) a b)) $ zip inputs patterns
|
||||
where inputs = map (getInputForIndex xs) [0..(length patterns)]
|
||||
|
||||
doSteps :: [Int] -> [[Int]] -> Int -> [Int]
|
||||
doSteps xs patterns cnt
|
||||
|
|
Loading…
Reference in New Issue
Block a user