Day16: Part1 works
This commit is contained in:
parent
ea5b4b48de
commit
5a307bfa6e
|
@ -0,0 +1,26 @@
|
||||||
|
import Data.Char
|
||||||
|
|
||||||
|
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 test1 = doSteps input patter 100
|
||||||
|
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
|
||||||
|
|
||||||
|
get :: [Int] -> Int
|
||||||
|
get xs = mod (abs $ (sum xs)) 10
|
||||||
|
|
||||||
|
step :: [Int] -> [[Int]] -> [Int]
|
||||||
|
step xs patterns = map ( get . zipWith (*) xs ) patterns
|
||||||
|
|
||||||
|
doSteps :: [Int] -> [[Int]] -> Int -> [Int]
|
||||||
|
doSteps xs patterns cnt
|
||||||
|
| cnt == 0 = xs
|
||||||
|
| otherwise = doSteps (step xs patterns) patterns (cnt -1)
|
Loading…
Reference in New Issue
Block a user