Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
1
Task/Repeat-a-string/Haskell/repeat-a-string-1.hs
Normal file
1
Task/Repeat-a-string/Haskell/repeat-a-string-1.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
concat $ replicate 5 "ha"
|
||||
1
Task/Repeat-a-string/Haskell/repeat-a-string-2.hs
Normal file
1
Task/Repeat-a-string/Haskell/repeat-a-string-2.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
[1..5] >> "ha"
|
||||
1
Task/Repeat-a-string/Haskell/repeat-a-string-3.hs
Normal file
1
Task/Repeat-a-string/Haskell/repeat-a-string-3.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
[1..5] *> "ha"
|
||||
1
Task/Repeat-a-string/Haskell/repeat-a-string-4.hs
Normal file
1
Task/Repeat-a-string/Haskell/repeat-a-string-4.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
cycle "ha"
|
||||
1
Task/Repeat-a-string/Haskell/repeat-a-string-5.hs
Normal file
1
Task/Repeat-a-string/Haskell/repeat-a-string-5.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
replicate 5 '*'
|
||||
9
Task/Repeat-a-string/Haskell/repeat-a-string-6.hs
Normal file
9
Task/Repeat-a-string/Haskell/repeat-a-string-6.hs
Normal 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
|
||||
25
Task/Repeat-a-string/Haskell/repeat-a-string-7.hs
Normal file
25
Task/Repeat-a-string/Haskell/repeat-a-string-7.hs
Normal 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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue