Cantor set: Difference between revisions
Content deleted Content added
→Haskell :: Dual representation: Tidied, pruned out one import. |
|||
Line 920: | Line 920: | ||
--------------------------- CANTOR ------------------------- |
--------------------------- CANTOR ------------------------- |
||
cantor :: (Rational, Rational) -> [[(Rational, Rational)]] |
cantor :: (Rational, Rational) -> [[(Rational, Rational)]] |
||
cantor = iterate (>>= go) . return |
cantor = iterate (>>= go) . return |
||
Line 928: | Line 929: | ||
---------------------------- TEST -------------------------- |
---------------------------- TEST -------------------------- |
||
main :: IO () |
main :: IO () |
||
main = do |
main = do |
||
Line 935: | Line 937: | ||
-------------------------- DISPLAY ------------------------- |
-------------------------- DISPLAY ------------------------- |
||
intervalBars :: [[(Rational, Rational)]] -> String |
intervalBars :: [[(Rational, Rational)]] -> String |
||
intervalBars xs = unlines $ go (d % 1) <$> xs |
intervalBars xs = unlines $ go (d % 1) <$> xs |
||
Line 943: | Line 946: | ||
mapAccumL |
mapAccumL |
||
(\a (rx, ry) -> |
(\a (rx, ry) -> |
||
let ( |
let (wy, wx) = (w * ry, w * rx) |
||
in ( wy |
in ( wy |
||
, replicate (floor (wx - a)) ' ' |
, replicate (floor (wx - a)) ' ' ++ |
||
replicate (floor (wy - wx)) '█')) |
|||
replicate (floor (wy - wx)) '█' -- interval bar. |
|||
)) |
|||
0 |
0 |
||
xs |
xs |