Skip to content

Instantly share code, notes, and snippets.

@jdiez17
Created December 1, 2014 11:20
Show Gist options
  • Save jdiez17/2acb5be4f61ed26f5419 to your computer and use it in GitHub Desktop.
Save jdiez17/2acb5be4f61ed26f5419 to your computer and use it in GitHub Desktop.
module Problem14 where
import Control.Monad.Writer
collatzWriter :: Int -> Writer [Int] ()
collatzWriter 1 = return ()
collatzWriter n = tell [next] >> collatzWriter next
where
next
| n `mod` 2 == 0 = n `div` 2
| otherwise = 3 * n + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment