Skip to content

Instantly share code, notes, and snippets.

@emilypi
Created January 9, 2019 21:21
Show Gist options
  • Save emilypi/46ad088df3d81605c5308508ad0c5d09 to your computer and use it in GitHub Desktop.
Save emilypi/46ad088df3d81605c5308508ad0c5d09 to your computer and use it in GitHub Desktop.
Tony's problem
reverse'' :: Int -> [a] -> [a] -> [a]
reverse'' n [] rs = drop n rs
reverse'' n as rs = h : t
where
h = case as of (a : as) -> head $ reverse'' n as (a : rs)
t = case as of (a : as) -> reverse'' (n + 1) as (a : rs)
reverse' :: [a] -> [a]
reverse' x = reverse'' 0 x []
main :: IO ()
main = do
print $ reverse' $ [1..10]
print $ length . take 1 . reverse' . reverse' $ [1..]
print $ length . take 50000 . reverse' . reverse' $ [1..]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment