Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
53
Task/Rep-string/Haskell/rep-string-2.hs
Normal file
53
Task/Rep-string/Haskell/rep-string-2.hs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import Data.Bool (bool)
|
||||
import Data.List (inits, intercalate, transpose)
|
||||
|
||||
------------------------ REP-CYCLES ----------------------
|
||||
|
||||
repCycles :: String -> [String]
|
||||
repCycles cs =
|
||||
filter
|
||||
((cs ==) . take n . cycle)
|
||||
((tail . inits) $ take (quot n 2) cs)
|
||||
where
|
||||
n = length cs
|
||||
|
||||
--------------------------- TEST -------------------------
|
||||
main :: IO ()
|
||||
main =
|
||||
putStrLn $
|
||||
fTable
|
||||
"Longest cycles:\n"
|
||||
id
|
||||
((flip bool "n/a" . last) <*> null)
|
||||
repCycles
|
||||
[ "1001110011",
|
||||
"1110111011",
|
||||
"0010010010",
|
||||
"1010101010",
|
||||
"1111111111",
|
||||
"0100101101",
|
||||
"0100100",
|
||||
"101",
|
||||
"11",
|
||||
"00",
|
||||
"1"
|
||||
]
|
||||
|
||||
------------------------- GENERIC ------------------------
|
||||
fTable ::
|
||||
String ->
|
||||
(a -> String) ->
|
||||
(b -> String) ->
|
||||
(a -> b) ->
|
||||
[a] ->
|
||||
String
|
||||
fTable s xShow fxShow f xs =
|
||||
let rjust n c = drop . length <*> (replicate n c <>)
|
||||
w = maximum (length . xShow <$> xs)
|
||||
in unlines $
|
||||
s :
|
||||
fmap
|
||||
( ((<>) . rjust w ' ' . xShow)
|
||||
<*> ((" -> " <>) . fxShow . f)
|
||||
)
|
||||
xs
|
||||
Loading…
Add table
Add a link
Reference in a new issue