Strange Loops

No Matter Where You Go, There You Are

A Solution to a Question

| Comments

A solution to the 3n + 1 problem in Haskell. A different solution to the one I gave in the coffee shop. This one is a little more conventional. The coffee shop solution did work though.

module Main wheremain :: Int -> Int -> Intmain i j = maximum $ map (\x -> f 0 x) [i..j]f :: Int -> Int -> Intf a 1 = a + 1f a m =     if m `mod` 2 == 1       then f (a + 1) (3 * m + 1)       else f (a + 1) (m `div` 2)