Skip to content

Instantly share code, notes, and snippets.

@jsoffer
Created January 28, 2011 15:09
Show Gist options
  • Save jsoffer/800359 to your computer and use it in GitHub Desktop.
Save jsoffer/800359 to your computer and use it in GitHub Desktop.
zipWithN f = foldl1 (zipWith f)
generar :: String -> [Int] -> [Bool]
generar inicial indices = ts where
ts = xs ++ zipWithN (/=) (g indices)
xs = map (== '1') inicial
g = map ((flip drop) ts)
leer n xs = take n $ map (\k -> if k then '1' else '0') xs
-- let t1 = generar "1001" [1,3]
-- "1001" cadena inicial
-- [1,3] los índices del registro que se suman
-- leer 100 t1 -- produce 100 bits con esos parámetros
-- cadena inicial no muy validada, '1' es '1', cualquier otra letra es '0'
-- no verifica si los índices rebasan la cadena inicial; puede causar ciclos
-- infinitos o errores en ese caso
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment