Cantor set: Difference between revisions

Content deleted Content added
Hout (talk | contribs)
Hout (talk | contribs)
Line 1,415: Line 1,415:
===Dual representation===
===Dual representation===
Intervals as fraction pairs, and intervals as graphic bars:
Intervals as fraction pairs, and intervals as graphic bars:
<lang haskell>import Data.List (intercalate, mapAccumL, maximumBy)
<lang haskell>import Control.Monad (join)
import Data.Bifunctor (bimap)
import Data.List (intercalate, mapAccumL, maximumBy)
import Data.Ratio (Ratio, denominator, numerator, (%))
import Data.Ratio (Ratio, denominator, numerator, (%))


Line 1,463: Line 1,465:
('(' :) . (<> ")")
('(' :) . (<> ")")
. intercalate ") ("
. intercalate ") ("
. fmap go
. fmap
(uncurry ((<>) . (<> ", ")) . join bimap showRatio)
where
go (rx, ry) = intercalate ", " $ showRatio <$> [rx, ry]


showRatio :: Rational -> String
showRatio :: Rational -> String
Line 1,472: Line 1,473:
go x
go x
| 1 /= x = '/' : show x
| 1 /= x = '/' : show x
| otherwise = []
| otherwise = []</lang>
</lang>
{{Out}}
{{Out}}
<pre>(0, 1)
<pre>(0, 1)