Talk:Man or boy test

From Wikipedia, the free encyclopedia

(nevermind) but, just how many levels of recursion is this supposed to have before anything returns? --Random832 03:06, 12 May 2007 (UTC)

PROC
name
Max depth of
recursions
Total
calls
a 512 722
b 511 721
  • Need a C0FFEE now?

I too am curious to know how/where/why Donald Knuth derived this strange algorithium. NevilleDNZ 09:32, 12 May 2007 (UTC) Well, that explains it. mozilla craps out after 1000 (i tried to implement it in javascript). --Random832 02:09, 18 May 2007 (UTC)

anyway, if anyone cares. C implementation

#include <stdio.h>
typedef struct s {
    int k;
    struct s *x1, *x2, *x3, *x4;
    int(*f)(struct s* ref);
} *ps;

int B(ps ref) {
    (ref->k)--;
    return A(ref->k,ref,ref->x1,ref->x2,ref->x3,ref->x4);
}

int A(int k, ps x1,ps x2,ps x3,ps x4,ps x5) {
    struct s x;
    x.x1=x1; x.x2=x2; x.x3=x3; x.x4=x4;
    x.k=k; x.f=B;
    if(x.k <= 0)
        return x4->f(x4) + x5->f(x5);
    else
        return B(&x);
}

int x(ps ref) {
    return ref->k;
}

int main() {
    struct s p; p.k= +1; p.f=x;
    struct s m; m.k= -1; m.f=x;
    struct s z; z.k=  0; z.f=x;
    int val = A(10,&p,&m,&m,&p,&z);
    printf("value is %d\n",val);
    return 0;
}

--Random832 02:09, 18 May 2007 (UTC).

Contents

[edit] Pending code snippet transplant/removal?

http://www.rosettacode.org/rosettacode/w/index.php?title=Talk:Man_or_boy_test —Preceding unsigned comment added by NevilleDNZ (talkcontribs) 00:32, 19 December 2007 (UTC)

[edit] Scheme

I turned the Common Lisp example into Scheme. Would it be useful to add that, given that there's already CL? Golwengaud (talk) 16:35, 24 December 2007 (UTC)

Yes, I believe it would. 70.111.126.237 (talk) 16:16, 3 January 2008 (UTC)
Done. Golwengaud (talk) 14:57, 6 January 2008 (UTC)

[edit] Common Lisp

There is a bug in the Common Lisp implementation: even with LET*, the scope of a local variable does not include its own initialization form, so the proposed solution does not in fact work (B is unbound). I intend to replace it shortly. 70.111.126.237 (talk) 16:16, 3 January 2008 (UTC)

[edit] Scala

Added a Scala implementation. This is without the object wrapper because you can run Scala programs directly as scripts. 128.214.11.51 (talk) 08:26, 17 March 2008 (UTC)