3n+1

Haskell でやってみた。

f :: Int -> [Int]
f n | n == 1         = [1]
    | n `mod` 2 == 0 = n : f (n `div` 2)
    | otherwise      = n : f (3 * n + 1)

max_seq :: Int -> Int -> Int
max_seq n m = foldl1 max $ map (length.f) [n..m]

process_line :: String -> IO ()
process_line line = let ns:ms:remain = words line
                        n = read ns
                        m = read ms
                    in putStrLn $ unwords $ map show $ [n, m, max_seq n m]

main = do cs <- getContents
          mapM_ process_line $ lines cs