Friday, April 4, 2014

Magical Recursion

These days, we almost finished studying recursion.
Recursion is a magical stuff. It begins from a simple figure and finally becomes a huge designed pic which composed with the original figures.

Let's talk about it.
Now I can do kind of questions or I can make up questions like that.
For example,

(define Qn (triangle 10 "solid""black"))

(define (Q n)
   (if (zero? n)
    Qn
(above
 (Q (sub1 n))
(beside
 (Q (sub1 n))
 (Q (sub1 n))))))

We can check expect that when n=0, it is a size 10, black solid triangle.
If n=1,2,3 and so on. We can see that this becomes a bigger and bigger triangle which composed the small black solid triangle.

This is so miraculous that I have ever know!!

No comments:

Post a Comment