git.iko.soy/rowtype-yoga/purescript-native
on 24fdff2 help sign in
18 lines 400 B history raw
1module Main where
3import Prelude
4import Control.Monad.Eff
5import Control.Monad.ST
7collatz :: Int -> Int
8collatz n = runPure (runST (do
9 r <- newSTRef n
10 count <- newSTRef 0
11 untilE $ do
12 modifySTRef count $ (+) 1
13 m <- readSTRef r
14 writeSTRef r $ if m `mod` 2 == 0 then m / 2 else 3 * m + 1
15 return $ m == 1
16 readSTRef count))
18main = Control.Monad.Eff.Console.print $ collatz 1000