Created
January 30, 2011 02:47
-
-
Save jsoffer/802466 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
-- LFSR, en formato compatible con | |
-- http://homepage.mac.com/afj/taplist.html | |
-- uso (en ghci): | |
-- > let t = ciclo 7 $ drop 7 $ leer $ generar "1111111" [7,6,4,2] | |
-- "1111111" es cadena inicial con 7 registros | |
-- [7, 6, 4, 2] es cuarteta en http://homepage.mac.com/afj/7bits.txt | |
-- 'ciclo 7' se detiene cuando se repite la secuencia de los 7 primeros símbolos | |
-- > t | |
-- "00111110110111000000101000011011 | |
-- 00100000111100010110101100001000 | |
-- 10011101111010001100110100110001 | |
-- 1100101010111010100100101111111" | |
-- > length t | |
-- 127 (2^7 - 1) | |
zipWithN f = foldl1 (zipWith f) | |
generar :: String -> [Int] -> [Bool] | |
generar inicial indices = ts where | |
n = length inicial | |
ts = xs ++ zipWithN (/=) (g indices) | |
xs = map (== '1') inicial | |
g = map (((flip drop) ts) . (n -)) | |
ciclo n (x:xs) = x : takeWhileNoCycle marca xs where | |
marca = take n (x:xs) | |
takeWhileNoCycle :: (Eq a) => [a] -> [a] -> [a] | |
takeWhileNoCycle mark (x:xs) = if (take (length mark) (x:xs)) == mark | |
then [] | |
else x : takeWhileNoCycle mark xs | |
leer = map (\k -> if k then '1' else '0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment