Skip to content

Instantly share code, notes, and snippets.

@jsoffer
Created February 27, 2011 12:42
Show Gist options
  • Save jsoffer/846151 to your computer and use it in GitHub Desktop.
Save jsoffer/846151 to your computer and use it in GitHub Desktop.
porTresMasUno :: [Bool] -> [Bool]
porTresMasUno xs = False : ys ++ residuo where
cs = True : zipWith3 gc cs (tail xs) xs
gc b = if b then (||) else (&&)
ys = zipWith3 gy cs (tail xs ++ [False]) xs
gy p q r = (p /= q) /= r
residuo = if last cs then [True] else []
serie :: String -> [[Bool]]
serie s = takeWhile (not.alto) $ iterate paso $ leer s where
leer = map (\k -> if k == '0' then False else True)
paso xs = ceros ++ siguiente where
(ceros,actual) = break id xs
siguiente = porTresMasUno actual
alto xs = (length $ filter id xs) == 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment