]> gerrit.simantics Code Review - simantics/platform.git/blob - Collaz.scl
08de951646c6e46a267a58d494e64296ecc14f4b
[simantics/platform.git] / Collaz.scl
1 import "Prelude"
2
3 f x = if x `mod` 2 == 0
4       then x `div` 2
5       else 3*x + 1
6 fd x = unfoldr (\x -> do
7                    r = f x 
8                    if x == 1
9                    then Nothing
10                    else Just (x,r)
11                 ) x
12
13 //main :: [Integer]                
14 main = fd 7
15 --
16 [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2]