Skip to content

Instantly share code, notes, and snippets.

@msysyamamoto
Created August 30, 2013 13:17
Show Gist options
  • Save msysyamamoto/6389758 to your computer and use it in GitHub Desktop.
Save msysyamamoto/6389758 to your computer and use it in GitHub Desktop.
{-
> halve []
([],[])
> halve [1]
([],[1])
> halve [1,2]
([1],[2])
> halve [1,2,3]
([1],[2,3])
> halve [1,2,3,4]
([1,2],[3,4])
-}
halve :: [a] -> ([a], [a])
halve xs = go xs xs
where
go (x:ys) (_:_:zs) = (x:us, vs)
where
(us, vs) = go ys zs
go ys _ = ([], ys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment