Created
August 18, 2010 20:07
-
-
Save abuiles/536000 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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