Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I write a program for Ackermann function in Stata?

    I wrote a program for the Ackermann function in Stata.
    The link below described how to do this using mata, but
    without using mata it would look like this, what am I doing wrong?

    https://rosettacode.org/wiki/Ackermann_function
    program ackermann, rclass
    gettoken a 0 : 0, parse(" ")
    gettoken b 0 : 0, parse(" ")

    confirm integer number `a'
    confirm integer number `b'

    if `a' == 0 {
    di `b' + 1
    return scalar N=`b' + 1
    }
    else if `a' > 0 & `b'==0 {
    local j=`a'-1
    ackermann `j' 1
    }
    else if `a' > 0 & `b' > 0 {
    local k=`b'-1
    qui ackermann `a' `k'
    local c=`r(N)'
    local h=`a'-1
    ackermann `h' `c'
    }
    end


    ackermann 0 1
    return list
    ackermann 1 0
    return list
    ackermann 1 1
    return list
Working...
X