Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °
| |
|
|
You are not logged in. #1 2012-12-20 06:15:16
LispTo start a little Lisp discussion, here are two functions I wrote: Code:(defun fibonacci (n)
(labels ((fib (n f)
(if (or (zerop n) (eq n -1))
(car f)
(fib (- n 1) (cons (+ (first f) (second f)) f ))
)))
(fib (- n 2) (1 1)))
)
(defun ints (n)
(labels ((f (n acc)
(if (zerop n)
acc
(f (- n 1) (cons n acc))
)))
(f n nil))
)The first one is for calculating the nth Fibonacci number, and the second for generating a list of the first n positive integers. Code:(mapcar #'fibonacci (ints 20)) Last edited by anonimnystefy (2012-12-20 07:40:07) The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #2 2012-12-20 20:37:36
Re: LispAnyone have an idea on what I could do next? The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #4 2012-12-20 21:12:41
Re: LispNot yet. I could learn that, though... The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #6 2012-12-20 21:42:43
Re: LispHow do I even start any work on graphics with Lisp? The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #7 2012-12-20 22:02:52
Re: LispOur friend Mr Google will give you plenty of hits. Lisp programmers seem to be pretty generous with their code/ideas. You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei #8 2012-12-20 22:04:24
Re: LispI tried Googling, but none of the things I tried worked... The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #10 2012-12-21 06:20:17
Re: LispI use SBCL for CLisp. The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #11 2012-12-21 11:33:33
Re: LispHi Bob The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #12 2012-12-21 14:52:57
Re: Lisphi Stefy You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei #13 2012-12-21 20:02:41
Re: LispHi Bob The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #14 2012-12-22 10:23:52
Re: LispHi Bob The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #16 2012-12-22 23:37:22
Re: LispHi Bob Code:(defun mandelbrot (size filename)
(let ((img (make-8-bit-gray-image size size)))
(declare (type 8-bit-gray-image img))
(loop for i from 1 to (1- size) do
(loop for j from 1 to (1- size) do ;these two loops go through all pixels of the image
(labels ((mb-set (x y nit) ;nit is the number of the iteration
(if (or (> (+ (* x x) (* y y)) 2) (> nit 1000)) ;this bit of code checks if the modulo of z is >2
(setf (pixel img i j) (round(/ 255.0 (1+ nit)))) ;if it is, this bit sets the current pixel to the appropriate shade of grey
(mb-set (+ (- (* x x) (* y y)) (/ (- j (round (/ size 2.0))) 50.0)) (+ (* 2 x y) (/ (- j (round (/ size 2.0))) 50.0)) (1+ nit)) ;if not, this bit sends new information into the next iteration
)
))
(mb-set 0.0 0.0 0)
)
)
)
(write-jpeg-file filename img)
)
)but it produces the picture below... Last edited by anonimnystefy (2012-12-23 01:09:52) The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #17 2012-12-23 00:31:27
Re: LispOk. A common mistake which you can easily fix: You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei #18 2012-12-23 01:05:55
Re: LispHi Bob The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #19 2012-12-23 01:07:55
Re: LispSorry. Was just about to re-edit that load of rubbish.
I see no i in that line. You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei #20 2012-12-23 01:16:29
Re: LispBob, you are brilliant! The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #21 2012-12-23 02:21:08
Re: LispThat's a great fractal. Well done! You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei #22 2012-12-23 02:34:47
Re: LispI am going with (i) first. The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #23 2013-05-18 14:21:56
Re: LispWould you give a link to download your compiler? Last edited by Agnishom (2013-05-18 14:27:05) 'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.' 'God exists because Mathematics is consistent, and the devil exists because we cannot prove it' 'The whole person changes, why can't a habit?' -65 |