r/school/ackermann.r · 667 字节 · 下载原文
# ackermann.r
# 来源 / Source: https://rosettacode.org/wiki/Ackermann_function
# 许可 / License: Rosetta Code 内容按 GNU FDL 1.3 发布(页面未另标许可)
# 说明 / Note: 函数定义 + 同页的驱动循环 / function def + the driver loop from the same page
# ─────────────────────────────────────────────────────────────
ackermann <- function(m, n) {
if ( m == 0 ) {
n+1
} else if ( n == 0 ) {
ackermann(m-1, 1)
} else {
ackermann(m-1, ackermann(m, n-1))
}
}
for ( i in 0:3 ) {
print(ackermann(i, 4))
}