utdrmac wrote:
> Here is my translated scheme. Again, I am not too familiar with it. I made
> this in about 20 min. If you have a better more efficient way, please pass
> is along.
>
> (define ackerman
> (lambda (m n)
> (cond ((= m 0)
> (* 2 n))
>
> ((and (>= m 1) (= n 0))
> 0)
>
> ((and (>= m 1) (= n 1))
> 2)
>
> (else
> (ackerman (- m 1) (ackerman m (- n 1)))))
> ))
your code is correct.
> I cannot get this one to work: (ackerman 3 4)
> I left my comp running for about 1 min before I stopped it and it still
> hadn't given me anything.
In order to understand what is happening, try annotating your
program so you can watch what's going on.
;=================clip==========================
;; first a function we can use to print the
;; value of something we're working with without stopping
;; the calculation.
(define print-and-return
(lambda (z)
(begin
(print z)
(print " ")
z)))
;; Then a slightly modified ackerman function
;; based on yours above.
(define ackerman
(lambda (m n)
(cond ((= m 0) (* 2 n))
((and (>= m 1) (= n 0)) 0)
((and (>= m 1) (= n 1)) 2)
(else
(ackerman (- m 1)
(print-and-return (ackerman m (- n 1))))))))
;==================clip=======================
This ackerman is just like your ackerman except that it
prints intermediate results as it finds them.
Running it won't get you results any better than the ones
you've already got, but running it should give you some
idea *why* you didn't get results when you tried it.
Bear
|