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

@ -0,0 +1,9 @@
repString :: String -> Int -> String
repString s n =
let rep x = xs
where
xs = mappend x xs
in take (n * length s) (rep s)
main :: IO ()
main = print $ repString "ha" 5

View file

@ -0,0 +1,25 @@
import Data.Tuple (swap)
import Data.List (unfoldr)
import Control.Monad (join)
-- BY RHIND PAPYRUS 'EGYPTIAN' OR 'ETHIOPIAN' MULTIPLICATION ------------------
repString :: Int -> String -> String
repString n s =
foldr
(\(d, x) a ->
if d > 0 -- Is this power of 2 needed for the binary recomposition ?
then mappend a x
else a)
mempty $
zip
(unfoldr
(\h ->
if h > 0
then Just $ swap (quotRem h 2) -- Binary decomposition of n
else Nothing)
n)
(iterate (join mappend) s) -- Iterative duplication ( mappend to self )
-- TEST -----------------------------------------------------------------------
main :: IO ()
main = print $ repString 500 "ha"