Math, Comp & Art

at Heart

I'm highly aware that I'm a guest in the language. I'm wondering if that's not the truth for all of us, that somehow we're all guests in language, that once we start speaking any language somehow we bow to that language at the same time we bend that language to us.
Li-Young Lee

May 31, 2016, 11:49 p.m.

Recursion in Scheme

By Maurice Ticas

Tags:

recursion

As promised from the "Update" Febuary 6th post, we can now recur to produce the total number of triangles inside the \(n^{th}\) iteration of the Sierpinski triangle using the code below written in Scheme.

1
2
3
4
5
(define sierpinski
  (lambda (n)
    (cond 
     ((zero? n) 1)
      (else (+ 1 (* 3 (sierpinski(- n 1))))))))


To do the recursion on your computer, install mit-scheme, then copy and paste the code to your mit-scheme implementation. You then will be able to call the function for any desirable \(n\). Now go ahead and recur!

There are 0 comments. No more comments are allowed.