Cantor set: Difference between revisions
Content deleted Content added
m →{{header|AppleScript}}: tidied. Added preamble. |
→Haskell :: Dual representation: Tidied, pruned out one import. |
||
Line 918:
<lang haskell>import Data.Ratio (Ratio, (%), numerator, denominator)
import Data.List (intercalate, mapAccumL, maximumBy)
--------------------------- CANTOR -------------------------
cantor :: (Rational, Rational) -> [[(Rational, Rational)]]
cantor = iterate (>>= go) . return
where
let go (x, y) =▼
go (x, y) =
in [(x, x + r), (y - r, y)]▼
---------------------------- TEST --------------------------
main :: IO ()
main = do
Line 933 ⟶ 934:
putStrLn $ intervalBars xs
intervalBars :: [[(Rational, Rational)]] -> String
intervalBars xs = unlines $ go (d % 1) <$> xs
where
d = maximum $
go w xs
concat . snd
mapAccumL
let
in ( wy -- Accumulator – end of
replicate (floor (wy - wx)) '█' -- interval bar.
▲ 0
0
intervalRatios :: [(Rational, Rational)] -> String
intervalRatios
where
showRatio :: Rational -> String
showRatio = ((++) . show . numerator) <*> (go . denominator)
where
| 1 /= x = '/' : show x
| otherwise = []</lang>
{{Out}}
<pre>(0, 1)
|