Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main where
- import Graphics.Gloss
- import Data.List
- main :: IO ()
- main = display (InWindow "Recaman Sequence" (500, 500) (0, 0)) white draw
- draw :: Picture
- draw = rotate (-35) $ pictures $ snd $ mapAccumL (addarc) [] (map (\n -> fromIntegral n :: Float) (recaman 65))
- where addarc acc n
- | acc == [] = (acc ++ [n], blank)
- | otherwise = (acc ++ [n], translate (last acc - (last acc - n) / 2) 0 $ rotarc $ arcbetween n (last acc))
- where arcbetween a b = arc (-180) 0 ((b - a)/2)
- rotarc a
- | even $ length acc = rotate 180 a
- | odd $ length acc = a
- recaman :: Int -> [Int]
- recaman l = foldl (next) [] [0..l]
- where next acc n
- | n == 0 = acc ++ [n]
- | last acc - n > 0 && not (last acc - n `elem` acc) = acc ++ [last acc - n]
- | otherwise = acc ++ [last acc + n]
Add Comment
Please, Sign In to add comment