haskell: add [p12, p17]
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
15
haskell/p14.hs
Normal file
15
haskell/p14.hs
Normal file
@@ -0,0 +1,15 @@
|
||||
import Data.Ord (comparing)
|
||||
import Data.List (maximumBy)
|
||||
|
||||
main :: IO ()
|
||||
main = putStr $ show $ fst $ maximumBy (comparing snd) $ zip range $ map collatz range
|
||||
where
|
||||
range :: [ Int ]
|
||||
range = [1 .. 10 ^ 6 - 1]
|
||||
|
||||
-- eh 12s isn't much
|
||||
collatz :: Int -> Int
|
||||
collatz n
|
||||
| n == 1 = 1
|
||||
| even n = 1 + collatz (div n 2)
|
||||
| otherwise = 1 + collatz (3 * n + 1)
|
Reference in New Issue
Block a user