Cantor set: Difference between revisions

Line 1,415:
===Dual representation===
Intervals as fraction pairs, and intervals as graphic bars:
<lang haskell>import DataControl.ListMonad (intercalate, mapAccumL, maximumByjoin)
import Data.Bifunctor (bimap)
import Data.List (intercalate, mapAccumL, maximumBy)
import Data.Ratio (Ratio, denominator, numerator, (%))
 
Line 1,463 ⟶ 1,465:
('(' :) . (<> ")")
. intercalate ") ("
. fmap go
(uncurry ((<>) . (<> ", ")) . join bimap showRatio)
where
go (rx, ry) = intercalate ", " $ showRatio <$> [rx, ry]
 
showRatio :: Rational -> String
Line 1,472 ⟶ 1,473:
go x
| 1 /= x = '/' : show x
| otherwise = []</lang>
</lang>
{{Out}}
<pre>(0, 1)
9,659

edits