Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,15 @@
import Data.Bool ( bool )
import Data.Complex (Complex ((:+)), magnitude)
mandelbrot :: RealFloat a => Complex a -> Complex a
mandelbrot a = iterate ((a +) . (^ 2)) 0 !! 50
main :: IO ()
main =
mapM_
putStrLn
[ [ bool ' ' '*' (2 > magnitude (mandelbrot (x :+ y)))
| x <- [-2, -1.9685 .. 0.5]
]
| y <- [1, 0.95 .. -1]
]

View file

@ -0,0 +1,13 @@
-- first attempt
-- putStrLn $ foldr (++) "" [ if x==(-2) then "\n" else let (a, b) = iterate (\(x', y') -> (x'^2-y'^2+x, 2*x'*y'+y)) (0, 0) !! 500 in (snd.head.filter (\(v, c)->v) $ zip ([(<0.01), (<0.025), (<0.05), (<0.1), (<0.5), (<1), (<4), (\_ -> True)] <*> [a^2 + b^2]) [".", "\'", ":", "!", "|", "}", "#", " "]) | y <- [1, 0.98 .. -1], x <- [-2, -1.98 .. 0.5]]
-- replaced iterate with foldr, modified the snd.head part and a introduced a check to stop the magnitude from exploding
-- foldr(>>)(return())[putStrLn[let(a,b)=foldr(\_(u,w)->if(u^2+w^2<4)then(u^2-w^2+x,2*u*w+y)else(u,w))(0,0)[1..500]in snd.last$(filter(\(f,v)->f)$zip(map(a^2+b^2>)[0,0.01,0.025,0.05,0.1,0.5,1,4])['.','\'',':','!','|','}','#',' '])|x<-[-2,-1.98..0.5]]|y<-[1,0.98.. -1]]
-- without different characters in the output
-- foldr(>>)(return())[putStrLn[let(a,b)=foldr(\_(u,w)->(u^2-w^2+x,2*u*w+y))(0,0)[1..500]in if a^2+b^2<4 then '*' else ' '|x<-[-2,-1.98..0.5]]|y<-[1,0.98.. -1]]
-- using mapM_ instead of foldr, bind operator instead of list comprehension and replacing 'let' with a lambda function
-- mapM_ putStrLn $[1,0.98.. -1]>>= \y->return $[-2,-1.98..0.5]>>= \x->return (if(\(a,b)->a^2+b^2<4)(foldr(\_(u,w)->(u^2-w^2+x,2*u*w+y))(0,0)[1..500]) then '*' else ' ')
-- open GHCI > Copy and paste any of above one-liners > Hit enter

View file

@ -0,0 +1,32 @@
main :: IO ()
main =
putStrLn $
concat
[ go x y
| y <- [1, 0.98 .. -1],
x <- [-2, -1.98 .. 0.5]
]
where
go x y
| x == (-2) = "\n"
| otherwise =
let (a, b) =
iterate
(\(x', y') -> (x' ^ 2 - y' ^ 2 + x, 2 * x' * y' + y))
(0, 0)
!! 500
in ( snd . head . filter fst $
zip
( [ (< 0.01),
(< 0.025),
(< 0.05),
(< 0.1),
(< 0.5),
(< 1),
(< 4),
const True
]
<*> [a ^ 2 + b ^ 2]
)
[".", "\'", ":", "!", "|", "}", "#", " "]
)

View file

@ -0,0 +1,20 @@
main :: IO ()
main =
mapM_
putStrLn
$ [1, 0.98 .. -1]
>>= \y ->
[ [-2, -1.98 .. 0.5]
>>= \x ->
[ if (\(a, b) -> a ^ 2 + b ^ 2 < 4)
( foldr
( \_ (u, w) ->
(u ^ 2 - w ^ 2 + x, 2 * u * w + y)
)
(0, 0)
[1 .. 500]
)
then '*'
else ' '
]
]