Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
18
Task/Hailstone-sequence/Haskell/hailstone-sequence-1.hs
Normal file
18
Task/Hailstone-sequence/Haskell/hailstone-sequence-1.hs
Normal 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]
|
||||
Loading…
Add table
Add a link
Reference in a new issue