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>
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▼
where
--------------------------- 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
showCantor :: [(Bool, Int)] -> String
showCantor = (
where
go (True, n) = replicate n '*'
▲main :: IO ()
{{Out}}
<pre>*********************************************************************************
|