freeCodeCamp/curriculum/challenges/chinese/08-coding-interview-prep/rosetta-code/hailstone-sequence.chinese.md

2.1 KiB
Raw Blame History

title id challengeType videoUrl localeTitle
Hailstone sequence 595608ff8bcd7a50bd490181 5 冰雹序列

Description

Hailstone数字序列可以从起始正整数n生成

如果n为1则序列结束。如果n是偶数那么序列的下一个n = n/2如果n是奇数那么序列的下一个n = (3 * n) + 1

(未经证实的) Collatz猜想是任何起始编号的冰雹序列总是终止。

冰雹序列也称为冰雹数因为这些值通常受到多个下降和上升如云中的冰雹或者作为Collatz序列。

任务创建例程以生成数字的hailstone序列。使用例程表明对于27号的冰雹序列具有开始与112个元件27, 82, 41, 124 ,结束时用8, 4, 2, 1与显示具有最长冰雹序列的数目少于100,000一起序列的长度。 (但不要显示实际的序列!)参见: xkcd (幽默)。

Instructions

Tests

tests:
  - text: <code>hailstoneSequence</code>是一个函数。
    testString: 'assert(typeof hailstoneSequence === "function", "<code>hailstoneSequence</code> is a function.");'
  - text: '<code>[[27,82,41,124,8,4,2,1], [351, 77031]]</code> <code>hailstoneSequence()</code>应返回<code>[[27,82,41,124,8,4,2,1], [351, 77031]]</code>'
    testString: 'assert.deepEqual(hailstoneSequence(), res, "<code>hailstoneSequence()</code> should return <code>[[27,82,41,124,8,4,2,1], [351, 77031]]</code>");'

Challenge Seed

// noprotect
function hailstoneSequence () {
  const res = [];
  // Good luck!

  return res;
}

After Test

console.info('after the test');

Solution

// solution required