scsh-users
[Top] [All Lists]

Re: Won't output...

To: scsh-news@zurich.ai.mit.edu
Subject: Re: Won't output...
From: "Joe Marshall" <prunesquallor@attbi.com>
Date: Thu, 18 Apr 2002 14:42:15 GMT
Organization: ATT Broadband
"utdrmac" <dr_mac@ev1.net> wrote in message
B8E3EE4E.2D01%dr_mac@ev1.net">news:B8E3EE4E.2D01%dr_mac@ev1.net...
> Hi. I am new to scheme and I am trying to get this to work correctly.
> This is a recursive function that crashes on my linux box with C++. I was
> told to get scheme cause it was made for recursion.
>
> This is Ackerman's function. You give it 2 integers: m and n
>
> If m = 0 return 2*n
> If m >= 1 and n=0 return 0
> If m >= 1 and n=1 return 2
> If m >= 1 and n>=2 then recursivly call 'ackerman(m-1, ackerman(m,n-1))'
>
> 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)))))
>             ))
>
>
> Here are some tests on the above code. All of these are correct.
>
> ; > (ackerman 1 0)
> ; 0
> ; > (ackerman 2 2)
> ; 4
> ; > (ackerman 2 3)
> ; 16
> ; > (ackerman 3 3)
> ; 65536
>
> 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.

It is *way* too big.  The lifetime of the universe is far too short
to calculate it this way, and you couldn't write down the answer in
decimal notation without running out of fundamental particles.




<Prev in Thread] Current Thread [Next in Thread>