Skip to content

Instantly share code, notes, and snippets.

@abuiles
Created August 18, 2010 20:07
Show Gist options
  • Save abuiles/536000 to your computer and use it in GitHub Desktop.
Save abuiles/536000 to your computer and use it in GitHub Desktop.
import Prelude hiding ( cycle )
import Control.Monad ( liftM )
cycle n c
| n == 1 = c
| odd n = cycle (3*n+1) c+1
| otherwise = cycle (div n 2) c+1
findMax i j = foldr (max . (`cycle` 1)) 0 [i..j]
getMax :: String -> IO ()
getMax values = do
let (a:b:_) = words values
putStrLn $ unwords [a,b,show (findMax (read a) (read b))]
main :: IO ()
main = do
cases <- lines `liftM` getContents
mapM_ getMax cases
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment