freeCodeCamp/curriculum/challenges/chinese/08-coding-interview-prep/rosetta-code/zeckendorf-number-represent...

1.9 KiB
Raw Blame History

title id challengeType videoUrl localeTitle
Zeckendorf number representation 594810f028c0303b75339ad6 5 勾选村号码表示

Description

正如数字可以用位置表示法表示为十(十进制)或二(二进制)的幂的倍数之和;所有正整数都可以表示为Fibonacci系列的不同成员的一次或零次的总和。

回想一下,第一六个不同斐波那契数是: 1, 2, 3, 5, 8, 13 。十进制数11可以用位置表示法写成0*13 + 1*8 + 0*5 + 1*3 + 0*2 + 0*1010100 其中列表示乘以序列的特定成员。前导零被丢弃因此十进制11变为10100

10100不是从斐波那契数字中得到11的唯一方法但是0*13 + 1*8 + 0*5 + 0*3 + 1*2 + 1*1或010011也代表十进制11。对于真正的Zeckendorf数字还有一个额外的限制即“不能使用两个连续的Fibonacci数”这导致了前一个独特的解决方案。

任务编写一个函数按顺序生成并返回前N个Zeckendorf数的数组。

Instructions

Tests

tests:
  - text: zeckendorf必须是功能
    testString: 'assert.equal(typeof zeckendorf, "function", "zeckendorf must be function");'
  - text: 你的<code>zeckendorf</code>函数应该返回正确的答案
    testString: 'assert.deepEqual(answer, solution20, "Your <code>zeckendorf</code> function should return the correct answer");'

Challenge Seed

function zeckendorf(n) {
  // good luck!
}

After Test

console.info('after the test');

Solution

// solution required