Created
June 3, 2016 09:19
-
-
Save dbalan/177863198ea6593cee14024d70d3f965 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
longest :: [Int] -> Int | |
longest ns = maybe 0 id $ elemIndex m zeroCount | |
where | |
zeroCount = tail $ scanl (\x y -> if (y == 0) then x+1 else 0) 1 ns | |
m = maximum zeroCount | |
cycleAtPoint :: [Int] -> [Int] | |
cycleAtPoint ns = take (length ns) $ drop (1 + longest ns) $ cycle ns | |
accum :: [Int] -> [Int] | |
accum ns = tail $ scanl (+) 0 ns | |
{- | |
segments :: [Int] -> [[Int]] | |
segments ns = undefined | |
where | |
accumulated = accum $ cycleAtPoint ns | |
matched = groupBy (\x y -> (x == y && x == 0) || (x /= 0 && y /= 0)) ns | |
operations :: [Int] -> Int | |
operations ns = (sum $ map length $ segments ns) - 1 | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment