September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,11 +1,17 @@
import Data.Tuple (swap)
import Data.List (unfoldr)
digSum base = sum . unfoldr f where
f 0 = Nothing
f n = Just (r,q) where (q,r) = n `divMod` base
digSum :: Int -> Int -> Int
digSum base = sum . unfoldr f
where
f 0 = Nothing
f n = Just (swap (quotRem n base))
digRoot base = head . dropWhile ((>= base).snd) . zip [0..] . iterate (digSum base)
digRoot :: Int -> Int -> (Int, Int)
digRoot base =
head . dropWhile ((>= base) . snd) . zip [0 ..] . iterate (digSum base)
main = do
putStrLn "in base 10:"
mapM_ print $ map (\x -> (x, digRoot 10 x)) [627615, 39390, 588225, 393900588225]
main :: IO ()
main = do
putStrLn "in base 10:"
mapM_ (print . ((,) <*> digRoot 10)) [627615, 39390, 588225, 393900588225]