Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,18 @@
import Data.List (maximumBy)
import Data.Ord (comparing)
main = do putStrLn $ "Collatz sequence for 27: "
++ ((show.hailstone) 27)
++ "\n"
++ "The number "
++ (show longestChain)
++" has the longest hailstone sequence"
++" for any number less then 100000. "
++"The sequence has length "
++ (show.length.hailstone $ longestChain)
hailstone = takeWhile (/=1) . (iterate collatz)
where collatz n = if even n then n `div` 2 else 3*n+1
longestChain = fst $ maximumBy (comparing snd) $
map ((\x -> (x,(length.hailstone) x))) [1..100000]