SHARE

TWEET

# Untitled

a guest
Sep 14th, 2018
57
Never

**Not a member of Pastebin yet?**

**, it unlocks many cool features!**

__Sign Up__- Looping over a function in Haskell
- split :: [a] -> ([a],[a])
- split xs = splitAt (length xs `div` 2) xs
- riffle :: [a] -> [a] -> [a]
- riffle xs [] = xs
- riffle [] ys = ys
- riffle (x:xs) (y:ys) = x:y:riffle xs ys
- shuffle :: Int -> [a] -> [a]
- shuffle 0 xs = xs
- shuffle n xs = shuffle (n-1) (riffle a b)
- where (a, b) = split xs
- riffle [1,2,3] [4,5,6] = [1,4,2,5,3,6]
- repeats :: [Int] -> Int
- > iterate (uncurry riffle . split) "ABCDEF"
- ["ABCDEF","ADBECF","AEDCBF","ACEBDF","ABCDEF","ADBECF","AEDCBF","ACEBDF", ...]
- > takeWhile (/= "ABCDEF") . tail $ iterate (uncurry riffle . split) "ABCDEF"
- ["ADBECF","AEDCBF","ACEBDF"]
- iterate f x = [x, f x, f (f x), f (f (f x)) ....]
- repeats xs = iter 1 (...) where
- iter n ys = if ys == xs
- then n
- else iter (...) (...)
- repeats xs = (...) $ takeWhile (...) $ iterate (shuffle 1) (...)

RAW Paste Data

We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.