September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,19 +1,26 @@
|
|||
import Data.List (maximumBy)
|
||||
import Data.Ord (comparing)
|
||||
import Data.List (maximumBy, intercalate)
|
||||
|
||||
hailstone :: Int -> [Int]
|
||||
hailstone 1 = [1]
|
||||
hailstone n | even n = n : hailstone (n `div` 2)
|
||||
| otherwise = n : hailstone (n * 3 + 1)
|
||||
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 :: (Int -> Int) -> Int -> (Int, Int)
|
||||
withResult f x = (f x, x)
|
||||
|
||||
h27 :: [Int]
|
||||
h27 = hailstone 27
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
let h27 = hailstone 27
|
||||
print $ length h27
|
||||
let h4 = show $ take 4 h27
|
||||
let t4 = show $ drop (length h27 - 4) h27
|
||||
putStrLn ("hailstone 27: " ++ h4 ++ " ... " ++ t4)
|
||||
print $ maximumBy (comparing fst) $ map (withResult (length . hailstone)) [1..100000]
|
||||
main =
|
||||
mapM_
|
||||
putStrLn
|
||||
[ (show . length) h27
|
||||
, "hailstone 27: " ++
|
||||
intercalate " ... " (show <$> [take 4 h27, drop (length h27 - 4) h27])
|
||||
, show $
|
||||
maximumBy (comparing fst) $
|
||||
withResult (length . hailstone) <$> [1 .. 100000]
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue