Cantor set: Difference between revisions

→‎{{header|Haskell}}: Tidied, pruned out an import.
(→‎{{header|JavaScript}}: Added headings to distinguish 3 representations)
(→‎{{header|Haskell}}: Tidied, pruned out an import.)
Line 1,340:
===Interval bars===
{{Trans|Python}} (Functional version)
<lang haskell>import-------------------------- Data.BoolCANTOR (bool)------------------------
 
cantor :: [(Bool, Int)] -> [(Bool, Int)]
cantor = (go =<<)
where
go (bln, n) =
| bln && 1 < n = [(True, m), (False, m), (True, m)]
let m = quot n 3
in| boolotherwise = [(bln, n)] [(True, m), (False, m), (True, m)] (bln && 1 < n)
where
let m = quot n 3
 
--------------------------- TEST -------------------------
main :: IO ()
main = putStrLn $ cantorLines 5
 
------------------------- DISPLAY ------------------------
cantorLines :: Int -> String
cantorLines n =
unlines $
unlines $ showCantor <$> take n (iterate cantor [(True, 3 ^ (n - 1))])
showCantor
unlines $ showCantor <$> take n (iterate cantor [(True, 3 ^ (n - 1))])
 
showCantor :: [(Bool, Int)] -> String
showCantor = (uncurry (flip replicate . bool ' ' '*')go =<<)
where
 
go (True, n) = replicate n '*'
main :: IO ()
main go (False, n) = putStrLnreplicate $n cantorLines' 5'</lang>
{{Out}}
<pre>*********************************************************************************
9,655

edits