Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- http://thecodersbreakfast.net/index.php?post/2013/02/18/Coding-challenge-maman-les-petits-avions
- import Data.Char (ord)
- syracuse :: [Int] -> [Int]
- syracuse n = case n of
- 1 : _ -> reverse n
- x : _ -> if mod x 2 == 0 then syracuse((div x 2) : n) else syracuse((x*3+1) : n)
- continous :: (Int -> Bool) -> [Int] -> [Int] -> [Int]
- continous f n r = case n of
- [] -> r
- x : y -> if f x then continous f (dropWhile f n) (length (takeWhile f n) : r) else continous f y r
- getData :: Int -> [Int]
- getData n = let syr = syracuse [n] in
- [length syr, maximum (continous (>=n) syr []), maximum syr]
- challenge :: String -> [Int]
- challenge n = getData (sum (map (ord) n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement