Tuesday, April 27, 2010

Ackermann's function funtime

So this weeks assignment, to get through section 1, seems like a chunky enough piece of work.

Especially when doing the exercises.

First contact with scheme has not been friendly. Lisp is an ugly language, and all those brackets are throwing me for more of a spin than pointers ever did.

But that aside, I got horribly side-tracked by the MIT definition of the ackermann function and the wikipedia one.
edit: they don't give the same results, and thank god for that because my expensions seemed to be all wrong.

MIT:


(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1)
(A x (- y 1))))))


The wikipedia method(converted to lisp for comparison)

(define (A m n)
(cond ((= m 0) (+ n 1))
((= n 0) (A (- m 1) 1))
(else (A (- m 1)
(A m (- n 1)))))
Should someone happen to be reading this that can offer some insight on this, please do let me know what's changed

No comments: