freeCodeCamp/curriculum/challenges/chinese/08-coding-interview-prep/rosetta-code/ackermann-function.chinese.md

1.8 KiB
Raw Blame History

title id challengeType videoUrl localeTitle
Ackermann function 594810f028c0303b75339acf 5 阿克曼功能

Description

Ackermann函数是递归函数的典型示例尤其值得注意的是它不是原始递归函数。它的值增长非常快其调用树的大小也是如此。

Ackermann函数通常定义如下

$$ Amn= \ begin {cases} n + 1\ mbox {if} m = 0 \\ Am-1,1\ mbox {if} m> 0 \ mbox {和} n = 0 \\ Am-1Amn-1\ mbox {if} m> 0 \ mbox {和} n> 0. \ end {cases} $$

它的论点永远不会消极,它总是终止。编写一个返回$ Amn$的值的函数。任意精度是首选(因为函数增长如此之快),但不是必需的。

Instructions

Tests

tests:
  - text: <code>ack</code>是一个功能。
    testString: 'assert(typeof ack === "function", "<code>ack</code> is a function.");'
  - text: '<code>ack(0, 0)</code>应该返回1。'
    testString: 'assert(ack(0, 0) === 1, "<code>ack(0, 0)</code> should return 1.");'
  - text: '<code>ack(1, 1)</code>应该返回3。'
    testString: 'assert(ack(1, 1) === 3, "<code>ack(1, 1)</code> should return 3.");'
  - text: '<code>ack(2, 5)</code>应该返回13。'
    testString: 'assert(ack(2, 5) === 13, "<code>ack(2, 5)</code> should return 13.");'
  - text: '<code>ack(3, 3)</code>应该返回61。'
    testString: 'assert(ack(3, 3) === 61, "<code>ack(3, 3)</code> should return 61.");'

Challenge Seed

function ack (m, n) {
  // Good luck!
}

Solution

// solution required