22 lines
938 B
Text
22 lines
938 B
Text
main :: [sys_message]
|
|
main = [Stdout h27m, Stdout biggestm]
|
|
where h27 = hailstone 27
|
|
h27n = #h27
|
|
h27f = take 4 h27
|
|
h27l = drop (h27n - 4) h27
|
|
h27m = "The hailstone sequence for 27 has " ++
|
|
show h27n ++ " elements starting with " ++
|
|
show h27f ++ " and ending with " ++
|
|
show h27l ++ "\n"
|
|
|
|
range = [1..100000]
|
|
biggest = max [#hailstone n | n<-range]
|
|
nbiggest = hd [n | n<-range; #hailstone n = biggest]
|
|
biggestm = "The number with the longest Hailstone " ++
|
|
"sequence < 100.000 is " ++ show nbiggest ++
|
|
" with length " ++ show biggest ++ "\n"
|
|
|
|
hailstone :: num->[num]
|
|
hailstone = (++[1]) . takewhile (>1) . iterate step
|
|
where step n = (3 * n) + 1, if n mod 2 = 1
|
|
= n div 2, otherwise
|