Yellowstone sequence: Difference between revisions
m
→{{header|Haskell}}: Tidied
m (→{{header|Haskell}}: Tidied) |
|||
Line 666:
and displaying a chart of the first 100 terms:
<lang haskell>import
import Data.Bifunctor (second)▼
import Diagrams.Backend.Rasterific▼
import Diagrams.Prelude▼
import Graphics.Rendering.Chart.Backend.Diagrams
import Graphics.Rendering.Chart.Easy
import qualified Graphics.SVGFonts.ReadFont as F
▲import Diagrams.Backend.Rasterific
▲import Diagrams.Prelude
▲import Data.Bifunctor (second)
----------------- YELLOWSTONE PERMUTATION
yellowstone :: [Integer]
yellowstone =
yellowstone = 1 : 2 : (active <$> iterate nextWindow (2, 3, [4 ..]))▼
1 :
2 :
where
nextWindow (p2, p1, rest) = (p1, n, residue)
where
[rp2, rp1] = relativelyPrime <$> [p2, p1]
go (x : xs)
| rp1 x && not (rp2 x) = (x, xs)
| otherwise = second ((:) x) (go xs)
Line 690 ⟶ 693:
relativelyPrime a b = 1 == gcd a b
---------- 30 FIRST TERMS, AND CHART OF FIRST 100
main :: IO (Image PixelRGBA8)
main = do
Line 697 ⟶ 700:
return $
chartRender env $
plot
plot (line "Yellowstone terms" [zip [1 ..] (take 100 yellowstone)])▼
( line
"Yellowstone terms"
)
--------------------- CHART GENERATION
chartRender ::
EC r () ->
Image PixelRGBA8
chartRender env ec =
renderDia
renderDia Rasterific (RasterificOptions (mkWidth (fst (envOutputSize env)))) $▼
Rasterific
fst $ runBackendR env (toRenderable (execEC ec))▼
( RasterificOptions
)
▲ $ fst $ runBackendR env (toRenderable (execEC ec))
------------------------ LOCAL FONT
chartEnv :: IO (DEnv Double)
chartEnv = do
Line 714 ⟶ 726:
sansRB <- F.loadFont "SourceSansPro_RB.svg"
let fontChosen fs =
case ( _font_name fs,
_font_slant fs,
("sans-serif", FontSlantNormal, FontWeightNormal) -> sansR▼
_font_weight fs
("sans-serif", FontSlantNormal, FontWeightBold) -> sansRB▼
) of
( "sans-serif",
) -> sansR
( "sans-serif",
FontSlantNormal,
FontWeightBold
) -> sansRB
return $ createEnv vectorAlignmentFns 640 400 fontChosen</lang>
{{Out}}
|