2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,4 @@
hailstone n
| n == 1 = 1
| even n = n `div` 2
| odd n = 3*n + 1

View file

@ -0,0 +1,2 @@
data Environment = Environment { count :: Int, value :: Int }
deriving Eq

View file

@ -0,0 +1 @@
environments = [ Environment 0 n | n <- [1..12] ]

View file

@ -0,0 +1,2 @@
process (Environment c 1) = Environment c 1
process (Environment c n) = Environment (c+1) (hailstone n)

View file

@ -0,0 +1,5 @@
process = execState $ do
n <- gets value
c <- gets count
when (n > 1) $ modify $ \env -> env { count = c + 1 }
modify $ \env -> env { value = hailstone n }

View file

@ -0,0 +1,13 @@
fixedPoint f x
| fx == x = [x]
| otherwise = x : fixedPoint f fx
where fx = f x
prettyPrint field = putStrLn . foldMap (format.field)
where format n = (if n < 10 then " " else "") ++ show n ++ " "
main = do
let result = fixedPoint (map process) environments
mapM_ (prettyPrint value) result
putStrLn (replicate 36 '-')
prettyPrint count (last result)

View file

@ -0,0 +1,6 @@
main = do
let result = map (fixedPoint process) environments
mapM_ (prettyPrint value) result
putStrLn (replicate 36 '-')
putStrLn "Counts: "
prettyPrint (count . last) result