You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.3 KiB

import Data.Char
main = do
cont <- getContents
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 $ take 8 test1)
getPatternForIndex :: [Int] -> Int -> Int -> [Int]
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 (\(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
| cnt == 0 = xs
| otherwise = doSteps (step xs patterns) patterns (cnt -1)
stepP2 :: [Int] -> Int -> [Int] -> [Int]
stepP2 xs sumIn acc
| sumIn == 0 = reverse acc
| sumIn > 0 = stepP2 (drop 1 xs) (sumIn - (head xs)) ((mod sumIn 10):acc)
doStepsP2 :: [Int] -> Int ->[Int]
doStepsP2 xs cnt
| cnt == 0 = xs
| otherwise = doStepsP2 (stepP2 xs (sum(xs)) []) (cnt -1)