Ad
Sequences
Arrays
Data Types
Code
Diff
  • module Collatz where
    
    collatz :: Int -> [Int]
    collatz = iterate next
      where next n | even n = n `div` 2
                   | odd n = n * 3 + 1
    • module Collatz where
    • collatz :: Int -> [Int]
    • collatz n = n : collatz next
    • where next | even n = n `div` 2
    • | odd n = n * 3 + 1
    • collatz = iterate next
    • where next n | even n = n `div` 2
    • | odd n = n * 3 + 1