Cantor set: Difference between revisions

Content deleted Content added
Hout (talk | contribs)
→‎Haskell :: Dual representation: Tidied, pruned out one import.
Hout (talk | contribs)
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 (wx, wy) = (w * rx, w * ry)
let (wy, wx) = (w * ry, w * rx)
in ( wy -- Accumulator – end of previous interval.
in ( wy
, replicate (floor (wx - a)) ' ' -- Preceding gap, and
, replicate (floor (wx - a)) ' ' ++
++
replicate (floor (wy - wx)) '█'))
replicate (floor (wy - wx)) '█' -- interval bar.
))
0
0
xs
xs