Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Hailstone-sequence/Frege/hailstone-sequence.frege
Normal file
20
Task/Hailstone-sequence/Frege/hailstone-sequence.frege
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
module Hailstone where
|
||||
|
||||
import Data.List (maximumBy)
|
||||
|
||||
hailstone :: Int -> [Int]
|
||||
hailstone 1 = [1]
|
||||
hailstone n | even n = n : hailstone (n `div` 2)
|
||||
| otherwise = n : hailstone (n * 3 + 1)
|
||||
|
||||
withResult :: (t -> t1) -> t -> (t1, t)
|
||||
withResult f x = (f x, x)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
let h27 = hailstone 27
|
||||
putStrLn $ show $ length h27
|
||||
let h4 = show $ take 4 h27
|
||||
let t4 = show $ drop (length h27 - 4) h27
|
||||
putStrLn ("hailstone 27: " ++ h4 ++ " ... " ++ t4)
|
||||
putStrLn $ show $ maximumBy (comparing fst) $ map (withResult (length . hailstone)) [1..100000]
|
||||
Loading…
Add table
Add a link
Reference in a new issue