fix: QA/Infosec update and python to chinese
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
2c78402837
commit
1cfa09adc4
@ -0,0 +1,64 @@
|
||||
---
|
||||
title: 100 doors
|
||||
id: 594810f028c0303b75339acb
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 100门
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>连续100个门都是最初关闭的。你可以在门口进行100次通行证。第一次通过,访问每扇门并“切换”门(如果门关闭,打开它;如果它打开,关闭它)。第二次,只访问每个第二个门(即门#2,#4,#6,......)并切换它。第三次,访问每个第3门(即3号门,#6号,#9号,......)等,直到您只访问第100个门。 </p><p>实现一个功能,以确定最后一次通过后门的状态。将最终结果返回到数组中,如果数组打开,则只包含数字中包含的门号。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>getFinalOpenedDoors</code>是一个函数。
|
||||
testString: assert(typeof getFinalOpenedDoors === 'function');
|
||||
- text: <code>getFinalOpenedDoors</code>应该返回一个数组。
|
||||
testString: assert(Array.isArray(getFinalOpenedDoors(100)));
|
||||
- text: <code>getFinalOpenedDoors</code>没有产生正确的结果。
|
||||
testString: assert.deepEqual(getFinalOpenedDoors(100), solution);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function getFinalOpenedDoors (numDoors) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,69 @@
|
||||
---
|
||||
title: 24 game
|
||||
id: 5951e88f64ebf159166a1176
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 24场比赛
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>实现一个以四位数字串为参数的函数,每个数字从1──►9(含),允许重复,并返回一个算术表达式,其值为24。如果不存在这样的解,则返回“没有解决方案。“ </p><p>规则: </p>只允许以下运算符/函数:乘法,除法,加法,减法除法应使用浮点或有理算术等来保留余数。不允许从提供的数字中形成多位数字。 (所以当给出1,2,2和1时,12 + 12的答案是错误的)。给定的数字顺序不必保留。 <p>示例输入: </p> <code>solve24("4878");</code> <code>solve24("1234");</code> <code>solve24("6789");</code> <code>solve24("1127");</code> <p>示例输出(字符串): </p> <code>(7-8/8)*4</code> <code>3*1*4*2</code> <code>(6*8)/(9-7)</code> <code>(1+7)*(2+1)</code> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>solve24</code>是一个函数。
|
||||
testString: assert(typeof solve24 === 'function');
|
||||
- text: <code>solve24("4878")</code>应返回<code>(7-8/8)*4</code>或<code>4*(7-8/8)</code>
|
||||
testString: assert(include(answers[0], solve24(testCases[0])));
|
||||
- text: <code>solve24("1234")</code>应返回<code>1*2*3*4</code>任何排列
|
||||
testString: assert(include(answers[1], solve24(testCases[1])));
|
||||
- text: <code>solve24("6789")</code>应返回<code>(6*8)/(9-7)</code>或<code>(8*6)/(9-7)</code>
|
||||
testString: assert(include(answers[2], solve24(testCases[2])));
|
||||
- text: <code>solve24("1127")</code>应该返回<code>(1+7)*(1*2)</code>的排列
|
||||
testString: assert(include(answers[3], solve24(testCases[3])));
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function solve24 (numStr) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,71 @@
|
||||
---
|
||||
title: 9 billion names of God the integer
|
||||
id: 5949b579404977fbaefcd736
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 90亿上帝的名字整数
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>这项任务是<a href="https://en.wikipedia.org/wiki/The Nine Billion Names of God#Plot_summary" title="wp:上帝的九十亿名字#Plot_summary">Arthur C. Clarke</a>的<a href="https://en.wikipedia.org/wiki/The Nine Billion Names of God#Plot_summary" title="wp:上帝的九十亿名字#Plot_summary">短篇小说改编</a> 。 </p><p> (求解者应该意识到完成这项任务的后果。) </p><p>详细说明,指定“名称”的含义: </p><p>整数1有1个名称“1”。 </p><p>整数2有2个名称“1 + 1”和“2”。 </p><p>整数3具有3个名称“1 + 1 + 1”,“2 + 1”和“3”。 </p><p>整数4具有5个名称“1 + 1 + 1 + 1”,“2 + 1 + 1”,“2 + 2”,“3 + 1”,“4”。 </p><p>整数5有7个名称“1 + 1 + 1 + 1 + 1”,“2 + 1 + 1 + 1”,“2 + 2 + 1”,“3 + 1 + 1”,“3 + 2”, “4 + 1”,“5”。 </p><p>这可以通过以下形式显示: </p><pre> 1
|
||||
1 1
|
||||
1 1 1
|
||||
1 2 1 1
|
||||
1 2 2 1 1
|
||||
1 3 3 2 1 1
|
||||
</pre><p>其中row $ n $对应于整数$ n $,而行$ m $中从左到右的每列$ C $对应于以$ C $开头的名称数。 </p><p> (可选)请注意$ n $ -th行$ P(n)$的总和是<a href="http://mathworld.wolfram.com/PartitionFunctionP.html" title="链接:http://mathworld.wolfram.com/PartitionFunctionP.html">整数分区函数</a> 。 </p>任务<p>实现一个返回$ n $ -th行之和的函数。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>numberOfNames</code>是一个函数。
|
||||
testString: assert(typeof numberOfNames === 'function');
|
||||
- text: <code>numberOfNames(5)</code>应该等于7。
|
||||
testString: assert.equal(numberOfNames(5), 7);
|
||||
- text: <code>numberOfNames(12)</code>应该等于77。
|
||||
testString: assert.equal(numberOfNames(12), 77);
|
||||
- text: <code>numberOfNames(18)</code>应该等于385。
|
||||
testString: assert.equal(numberOfNames(18), 385);
|
||||
- text: <code>numberOfNames(23)</code>应该等于1255。
|
||||
testString: assert.equal(numberOfNames(23), 1255);
|
||||
- text: <code>numberOfNames(42)</code>应该等于53174。
|
||||
testString: assert.equal(numberOfNames(42), 53174);
|
||||
- text: <code>numberOfNames(123)</code>应该等于2552338241。
|
||||
testString: assert.equal(numberOfNames(123), 2552338241);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function numberOfNames (num) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,74 @@
|
||||
---
|
||||
title: ABC Problem
|
||||
id: 594810f028c0303b75339acc
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: ABC问题
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>您将获得ABC块的集合(例如,童年字母块)。每个街区有20个街区,两个字母。块的所有侧面都保证有完整的字母表。块的样本集合: </p><p> (BO) </p><p> (XK) </p><p> (DQ) </p><p> (CP) </p><p> (NA) </p><p> (GT) </p><p> (回覆) </p><p> (TG) </p><p> (QD) </p><p> (FS) </p><p> (JW) </p><p> (HU) </p><p> (VI) </p><p> (一个) </p><p> (OB) </p><p> (ER) </p><p> (FS) </p><p> (LY) </p><p> (PC) </p><p> (ZM) </p><p>要记住一些规则: </p>一旦使用了块上的字母,就不能再使用该块。该函数应该不区分大小写。 <p>实现一个带字符串(单词)的函数,并确定该单词是否可以与给定的块集合拼写。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>canMakeWord</code>是一个功能。
|
||||
testString: assert(typeof canMakeWord === 'function');
|
||||
- text: <code>canMakeWord</code>应该返回一个布尔值。
|
||||
testString: assert(typeof canMakeWord('hi') === 'boolean');
|
||||
- text: <code>canMakeWord("bark")</code>应该返回true。
|
||||
testString: assert(canMakeWord(words[0]));
|
||||
- text: <code>canMakeWord("BooK")</code>应该返回false。
|
||||
testString: assert(!canMakeWord(words[1]));
|
||||
- text: <code>canMakeWord("TReAT")</code>应该返回true。
|
||||
testString: assert(canMakeWord(words[2]));
|
||||
- text: <code>canMakeWord("COMMON")</code>应返回false。
|
||||
testString: assert(!canMakeWord(words[3]));
|
||||
- text: <code>canMakeWord("squAD")</code>应该返回true。
|
||||
testString: assert(canMakeWord(words[4]));
|
||||
- text: <code>canMakeWord("conFUSE")</code>应该返回true。
|
||||
testString: assert(canMakeWord(words[5]));
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function canMakeWord (word) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,66 @@
|
||||
---
|
||||
title: 'Abundant, deficient and perfect number classifications'
|
||||
id: 594810f028c0303b75339acd
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 丰富,不足和完善的数字分类
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>它们根据<a href="http://rosettacode.org/wiki/Proper divisors" title="适当的除数">适当的除数</a>定义了三个正整数分类。 </p><p>设$ P(n)$是n的适当除数的总和,其中适当的除数都是n本身以外的正整数。 </p><p>如果<code>P(n) < n</code>那么n被归类为“缺陷” </p><p>如果<code>P(n) === n</code>那么n被归类为“完美” </p><p>如果<code>P(n) > n</code>则n被归类为“丰富” </p><p>例: </p><p> 6具有1,2和3的适当除数。 </p><p> 1 + 2 + 3 = 6,因此6被归类为完美数字。 </p><p>实现一个函数,计算三个类中每个类中1到20,000(包括)的整数。以下列格式将结果输出为数组<code>[deficient, perfect, abundant]</code> 。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>getDPA</code>是一个功能。
|
||||
testString: assert(typeof getDPA === 'function');
|
||||
- text: <code>getDPA</code>应该返回一个数组。
|
||||
testString: assert(Array.isArray(getDPA(100)));
|
||||
- text: <code>getDPA</code>返回值的长度应为3。
|
||||
testString: assert(getDPA(100).length === 3);
|
||||
- text: '<code>getDPA(20000)</code>应该等于[15043,4,4953]'
|
||||
testString: assert.deepEqual(getDPA(20000), solution);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function getDPA (num) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,66 @@
|
||||
---
|
||||
title: Accumulator factory
|
||||
id: 594810f028c0303b75339ace
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 蓄能器工厂
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>创建一个带有单个(数字)参数的函数,并返回另一个作为累加器的函数。返回的累加器函数又接受一个数字参数,并返回到目前为止传递给该累加器的所有数值的总和(包括创建累加器时传递的初始值)。 </p><p>规则: </p><p>不要使用全局变量。 </p><p>暗示: </p><p>闭包可以保存外部状态。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>accumulator</code>是一个功能。
|
||||
testString: assert(typeof accumulator === 'function');
|
||||
- text: <code>accumulator(0)</code>应该返回一个函数。
|
||||
testString: assert(typeof accumulator(0) === 'function');
|
||||
- text: <code>accumulator(0)(2)</code>应该返回一个数字。
|
||||
testString: assert(typeof accumulator(0)(2) === 'number');
|
||||
- text: '传递值3,-4,1.5和5应返回5.5。'
|
||||
testString: assert(testFn(5) === 5.5);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function accumulator (sum) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,60 @@
|
||||
---
|
||||
title: Ackermann function
|
||||
id: 594810f028c0303b75339acf
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 阿克曼功能
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p> Ackermann函数是递归函数的典型示例,尤其值得注意的是它不是原始递归函数。它的值增长非常快,其调用树的大小也是如此。 </p><p> Ackermann函数通常定义如下: </p> $$ A(m,n)= \ begin {cases} n + 1&\ mbox {if} m = 0 \\ A(m-1,1)&\ mbox {if} m> 0 \ mbox {和} n = 0 \\ A(m-1,A(m,n-1))&\ mbox {if} m> 0 \ mbox {和} n> 0. \ end {cases} $$ <p>它的论点永远不会消极,它总是终止。编写一个返回$ A(m,n)$的值的函数。任意精度是首选(因为函数增长如此之快),但不是必需的。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>ack</code>是一个功能。
|
||||
testString: assert(typeof ack === 'function');
|
||||
- text: '<code>ack(0, 0)</code>应该返回1。'
|
||||
testString: assert(ack(0, 0) === 1);
|
||||
- text: '<code>ack(1, 1)</code>应该返回3。'
|
||||
testString: assert(ack(1, 1) === 3);
|
||||
- text: '<code>ack(2, 5)</code>应该返回13。'
|
||||
testString: assert(ack(2, 5) === 13);
|
||||
- text: '<code>ack(3, 3)</code>应该返回61。'
|
||||
testString: assert(ack(3, 3) === 61);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function ack (m, n) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,89 @@
|
||||
---
|
||||
title: Align columns
|
||||
id: 594810f028c0303b75339ad0
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 对齐列
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>给定一个包含许多行的文本文件,其中一行中的字段由单个<code>$</code>字符描述,编写一个程序,通过确保每列中的单词至少由一个空格分隔来对齐每列字段。此外,允许列中的每个单词在其列中左对齐,右对齐或居中对齐。 </p><p>使用以下文本测试您的程序: </p><pre>的$ $多行给出$ A $文本$文件$
|
||||
其中$领域内$ A $线$ $
|
||||
是$由$ A $单个$ '美元' $字符划定$
|
||||
写$ A $程序
|
||||
即$对齐$ $场的每个$列$
|
||||
由$ $确保该$字美元$ $每
|
||||
列$ $是在$最少$一张价值$空间被分隔$ $。
|
||||
此外,$允许为$ $ $中的每个字$ $ A $ $列到$为$要么离开$ $
|
||||
对齐,右$ $有道理
|
||||
或$ $中心内$有道理$ $其列。
|
||||
</pre><p>注意: </p>示例输入文本行可以或可以不具有尾随美元字符。所有列应共享相同的对齐方式。为了完成任务,在行尾附近产生的连续空格字符是无关紧要的。输出文本将以纯文本编辑器或基本终端上的单行间隔字体查看。列之间的最小间距应根据文本计算,而不是硬编码。不需要在列之间或列周围添加分隔字符。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>formatText</code>是一个函数。
|
||||
testString: assert(typeof formatText === 'function');
|
||||
- text: 具有上述输入和“右”对齐的<code>formatText</code>应产生以下内容:
|
||||
testString: 'assert.strictEqual(formatText(testInput, ''right''), rightAligned);'
|
||||
- text: 具有上述输入和“左”对齐的<code>formatText</code>应产生以下内容:
|
||||
testString: 'assert.strictEqual(formatText(testInput, ''left''), leftAligned);'
|
||||
- text: 具有上述输入和“居中”对齐的<code>formatText</code>应产生以下内容:
|
||||
testString: 'assert.strictEqual(formatText(testInput, ''center''), centerAligned);'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
const testArr = [
|
||||
'Given$a$text$file$of$many$lines',
|
||||
'where$fields$within$a$line$',
|
||||
'are$delineated$by$a$single$"dollar"$character',
|
||||
'write$a$program',
|
||||
'that$aligns$each$column$of$fields$',
|
||||
'by$ensuring$that$words$in$each$',
|
||||
'column$are$separated$by$at$least$one$space.',
|
||||
'Further,$allow$for$each$word$in$a$column$to$be$either$left$',
|
||||
'justified,$right$justified',
|
||||
'or$center$justified$within$its$column.'
|
||||
];
|
||||
|
||||
function formatText (input, justification) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
title: Amicable pairs
|
||||
id: 5949b579404977fbaefcd737
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 友好的对
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">如果$ N \ neq M $和N $ $的<a href="http://rosettacode.org/wiki/Proper divisors" title="适当的除数">适当除数之</a>和($ \ mathrm {sum}(\ mathrm {propDivs}(N)),两个整数$ N $和$ M $被认为是<a href="https://en.wikipedia.org/wiki/Amicable numbers" title="wp:友善号码">友好对</a> $)$ = M $以及$ \ mathrm {sum}(\ mathrm {propDivs}(M))= N $。示例:1184和1210是友好对,具有适当的除数:1,2,4,8,16,32,37,74,148,296,592和1,2,5,10,11,25,55,分别为110,121,242,605。任务:计算并显示低于20,000的Amicable对(有八个)。相关任务<a href="http://rosettacode.org/wiki/Proper divisors" title="适当的除数">适当的除数</a> <a href="http://rosettacode.org/wiki/Abundant, deficient and perfect number classifications" title="丰富,不足和完善的数字分类">丰富,缺陷和完善的数字分类</a> <a href="http://rosettacode.org/wiki/Aliquot sequence classifications" title="等分序列分类">等分序列分类</a>及其友好分类。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>amicablePairsUpTo</code>是一个函数。
|
||||
testString: assert(typeof amicablePairsUpTo === 'function');
|
||||
- text: '<code>[[220,284]]</code> <code>amicablePairsUpTo(300)</code>应返回<code>[[220,284]]</code> 。'
|
||||
testString: assert.deepEqual(amicablePairsUpTo(300), answer300);
|
||||
- text: '<code>[[220,284],[1184,1210],[2620,2924]]</code> <code>amicablePairsUpTo(3000)</code>应返回<code>[[220,284],[1184,1210],[2620,2924]]</code> 。'
|
||||
testString: assert.deepEqual(amicablePairsUpTo(3000), answer3000);
|
||||
- text: '<code>[[220,284],[1184,1210],[2620,2924],[5020,5564],[6232,6368],[10744,10856],[12285,14595],[17296,18416]]</code> <code>amicablePairsUpTo(20000)</code>应返回<code>[[220,284],[1184,1210],[2620,2924],[5020,5564],[6232,6368],[10744,10856],[12285,14595],[17296,18416]]</code> 。'
|
||||
testString: assert.deepEqual(amicablePairsUpTo(20000), answer20000);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function amicablePairsUpTo (maxNum) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,65 @@
|
||||
---
|
||||
title: Averages-Mode
|
||||
id: 594d8d0ab97724821379b1e6
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 平均值模式
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>编写程序以查找集合的<a href="https://en.wikipedia.org/wiki/Mode (statistics)" title="wp:模式(统计)">模式</a>值。 </p><p>可以忽略集合为空的情况。必须小心处理模式不唯一的情况。 </p><p>如果不适合或不可能支持常规集合,请尽可能使用向量(数组)。如果不适合或不可能支持未指定的值类型,请使用整数。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>mode</code>是一种功能。
|
||||
testString: assert(typeof mode === 'function');
|
||||
- text: '<code>mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17])</code>应该相等<code>[6]</code>'
|
||||
testString: assert.deepEqual(mode(arr1), [6]);
|
||||
- text: '<code>mode([1, 2, 4, 4, 1])</code>应该等于<code>[1, 4]</code> 。'
|
||||
testString: assert.deepEqual(mode(arr2).sort(), [1, 4]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function mode (arr) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,70 @@
|
||||
---
|
||||
title: Averages-Pythagorean means
|
||||
id: 594d966a1467eb84194f0086
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 平均值 - 毕达哥拉斯指的是
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p class="rosetta__paragraph">计算整数<big>1</big>到<big>10</big> (包括)的所有三个<a class="rosetta__link--wiki" href="https://en.wikipedia.org/wiki/Pythagorean means" title="wp:毕达哥拉斯意味着">毕达哥拉斯方法</a> 。 </p><p class="rosetta__paragraph">为这组正整数显示<big>$ A(x_1,\ ldots,x_n)\ geq G(x_1,\ ldots,x_n)\ geq H(x_1,\ ldots,x_n)$</big> 。 </p>这三种方法中最常见的<a class="rosetta__link--rosetta" href="http://rosettacode.org/wiki/Averages/Arithmetic mean" title="平均值/算术平均值">算术平均值</a>是列表的总和除以其长度: <big>$ A(x_1,\ ldots,x_n)= \ frac {x_1 + \ cdots + x_n} {n} $</big> <a class="rosetta__link--wiki" href="https://en.wikipedia.org/wiki/Geometric mean" title="wp:几何平均值">几何mean</a>是列表产品的$ n $ th根: <big>$ G(x_1,\ ldots,x_n)= \ sqrt [n] {x_1 \ cdots x_n} $</big> <a class="rosetta__link--wiki" href="https://en.wikipedia.org/wiki/Harmonic mean" title="wp:谐波意味着">调和平均值</a>是$ n $除以总和列表中每个项目的倒数: <big>$ H(x_1,\ ldots,x_n)= \ frac {n} {\ frac {1} {x_1} + \ cdots + \ frac {1} {x_n}} $</big> <p class="rosetta__paragraph">假设输入是包含所有数字的有序数组。 </p><p class="rosetta__paragraph">要获得答案,请按以下格式输出对象: </p><pre class="rosetta__pre"> {
|
||||
值:{
|
||||
算术:5.5,
|
||||
几何:4.528728688116765,
|
||||
谐波:3.414171521474055
|
||||
},
|
||||
测试:'是A> = G> = H?是'
|
||||
}
|
||||
</pre></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>pythagoreanMeans</code>是一种功能。
|
||||
testString: assert(typeof pythagoreanMeans === 'function');
|
||||
- text: '<code>pythagoreanMeans([1, 2, ..., 10])</code>应该等于上面相同的输出。'
|
||||
testString: assert.deepEqual(pythagoreanMeans(range1), answer1);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function pythagoreanMeans (rangeArr) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,62 @@
|
||||
---
|
||||
title: Averages-Root mean square
|
||||
id: 594da033de4190850b893874
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 平均值 - 均方根
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>计算数字1到10(包括1和10)的<a href="https://en.wikipedia.org/wiki/Root mean square" title="wp:均方根">均方根</a> 。 </p><p>均方根也以其首字母RMS(或rms)和二次均值来表示。 </p><p> RMS计算为数字平方的平均值,平方根: </p><p> <big>$$ x _ {\ mathrm {rms}} = \ sqrt {{{x_1} ^ 2 + {x_2} ^ 2 + \ cdots + {x_n} ^ 2} \ over n}。 $$</big> </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>rms</code>是一个功能。
|
||||
testString: assert(typeof rms === 'function');
|
||||
- text: '<code>rms([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])</code>应等于<code>6.2048368229954285</code> 。'
|
||||
testString: assert.equal(rms(arr1), answer1);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function rms (arr) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,63 @@
|
||||
---
|
||||
title: Babbage problem
|
||||
id: 594db4d0dedb4c06a2a4cefd
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 巴贝奇问题
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p> <a href="https://en.wikipedia.org/wiki/Charles_Babbage" title="wp:Charles_Babbage">Charles Babbage</a> ,展望他的分析引擎能解决的各种问题,给出了这个例子: </p><blockquote>什么是正方形以数字269,696结尾的最小正整数? </blockquote><p> - 巴贝奇,致鲍登勋爵的信,1837年;见Hollingdale和Tootill, <i>电子计算机</i> ,第二版,1970年,p。 125。 </p><p>他认为答案可能是99,736,其平方是9,947,269,696;但他无法确定。 </p><p>任务是找出巴贝奇是否有正确的答案。 </p><p>实现一个函数来返回满足Babbage问题的最小整数。如果巴贝奇是对的,返回巴贝奇的号码。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>babbage</code>是一种功能。
|
||||
testString: assert(typeof babbage === 'function');
|
||||
- text: '<code>babbage(99736, 269696)</code>不应该返回99736(答案较小)。'
|
||||
testString: assert.equal(babbage(babbageAns, endDigits), answer);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function babbage (babbageNum, endDigits) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,97 @@
|
||||
---
|
||||
title: Balanced brackets
|
||||
id: 594dc6c729e5700999302b45
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 平衡括号
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>确定生成的括号字符串是否平衡;也就是说,它是否完全由成对的开/关括号(按此顺序)组成,其中没有一个错误嵌套。 </p>例子: <p class="rosetta__paragraph"> (空)是的</p><p class="rosetta__paragraph"> <code>[]</code>是的</p><p class="rosetta__paragraph"> <code>][</code>假</p><p class="rosetta__paragraph"> <code>[][]</code>是的</p><p class="rosetta__paragraph"> <code>][][</code>假</p><p class="rosetta__paragraph"> <code>[]][[]</code> false </p><p class="rosetta__paragraph"> <code>[[[[]]]]</code>是的</p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>isBalanced</code>是一个函数。
|
||||
testString: assert(typeof isBalanced === 'function');
|
||||
- text: <code>isBalanced("[]")</code>应该返回true。
|
||||
testString: assert(isBalanced(testCases[0]));
|
||||
- text: <code>isBalanced("]][[[][][][]][")</code>应该返回false。
|
||||
testString: assert(!isBalanced(testCases[1]));
|
||||
- text: <code>isBalanced("[][[[[][][[[]]]]]]")</code>应该返回true。
|
||||
testString: assert(isBalanced(testCases[2]));
|
||||
- text: <code>isBalanced("][")</code>应该返回true。
|
||||
testString: assert(!isBalanced(testCases[3]));
|
||||
- text: <code>isBalanced("[[[]]]][[]")</code>应该返回true。
|
||||
testString: assert(!isBalanced(testCases[4]));
|
||||
- text: <code>isBalanced("][[]")</code>应该返回true。
|
||||
testString: assert(!isBalanced(testCases[5]));
|
||||
- text: <code>isBalanced("][[][]][[[]]")</code>应该返回true。
|
||||
testString: assert(!isBalanced(testCases[6]));
|
||||
- text: <code>isBalanced("[[][]]][")</code>应该返回true。
|
||||
testString: assert(!isBalanced(testCases[7]));
|
||||
- text: <code>isBalanced("[[[]]][[]]]][][[")</code>应该返回true。
|
||||
testString: assert(!isBalanced(testCases[8]));
|
||||
- text: <code>isBalanced("[]][[]]][[[[][]]")</code>应该返回true。
|
||||
testString: assert(!isBalanced(testCases[9]));
|
||||
- text: <code>isBalanced("][]][[][")</code>应该返回true。
|
||||
testString: assert(!isBalanced(testCases[10]));
|
||||
- text: <code>isBalanced("[[]][[][]]")</code>应该返回true。
|
||||
testString: assert(isBalanced(testCases[11]));
|
||||
- text: <code>isBalanced("[[]]")</code>应该返回true。
|
||||
testString: assert(isBalanced(testCases[12]));
|
||||
- text: <code>isBalanced("]][]][[]][[[")</code>应该返回true。
|
||||
testString: assert(!isBalanced(testCases[13]));
|
||||
- text: <code>isBalanced("][]][][[")</code>应该返回true。
|
||||
testString: assert(!isBalanced(testCases[14]));
|
||||
- text: <code>isBalanced("][][")</code>应该返回true。
|
||||
testString: assert(!isBalanced(testCases[15]));
|
||||
- text: <code>isBalanced("[[]]][][][[]][")</code>应该返回true。
|
||||
testString: assert(!isBalanced(testCases[16]));
|
||||
- text: <code>isBalanced("")</code>应该返回true。
|
||||
testString: assert(isBalanced(testCases[17]));
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function isBalanced (str) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,77 @@
|
||||
---
|
||||
title: Circles of given radius through two points
|
||||
id: 5951815dd895584b06884620
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 给定半径的圆圈通过两个点
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>给定平面上的两个点和半径,通常可以通过这些点绘制给定半径的两个圆。 </p>例外:零半径应视为从不描述圆(除非点是重合的)。如果这些点是重合的,则可以绘制无限数量的圆,其圆周上的点可以被绘制,除非半径也等于零,然后将圆圈折叠到一个点。如果点形成直径,则返回单个圆。如果这些点相距太远则无法绘制圆圈。任务:实现一个取两个点和一个半径的函数,并通过这些点返回两个圆。对于每个结果圆,提供每个圆的中心的坐标,四舍五入到四个十进制数字。将每个坐标作为数组返回,并作为数组数组进行坐标。对于边缘情况,请返回以下内容:如果点在直径上,则返回一个点。如果半径也为零,则返回<code>"Radius Zero"</code> 。如果点重合,则返回<code>"Coincident point. Infinite solutions"</code> 。如果点与直径相距更远,则返回<code>"No intersection. Points further apart than circle diameter"</code>更远的<code>"No intersection. Points further apart than circle diameter"</code> 。样本输入: <pre> p1 p2 r
|
||||
0.1234,0.9876 0.8765,0.2345 2.0
|
||||
0.0000,2.000000 0.0000,0.0000 1.0
|
||||
0.1234,0.9876 0.1234,0.9876 2.0
|
||||
0.1234,0.9876 0.8765,0.2345 0.5
|
||||
0.1234,0.9876 0.1234,0.9876 0.0
|
||||
</pre>参考:从数学论坛@Drexel的<a href="http://mathforum.org/library/drmath/view/53027.html" title="链接:http://mathforum.org/library/drmath/view/53027.html">2点和半径中找到一个</a>圆心</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>getCircles</code>是一个函数。
|
||||
testString: assert(typeof getCircles === 'function');
|
||||
- text: '<code>getCircles([0.1234, 0.9876], [0.8765, 0.2345], 2.0)</code>应该返回<code>[[1.8631, 1.9742], [-0.8632, -0.7521]]</code> 。'
|
||||
testString: assert.deepEqual(getCircles(...testCases[0]), answers[0]);
|
||||
- text: '<code>getCircles([0.0000, 2.0000], [0.0000, 0.0000], 1.0)</code>应该返回<code>[0, 1]</code>'
|
||||
testString: assert.deepEqual(getCircles(...testCases[1]), answers[1]);
|
||||
- text: '<code>getCircles([0.1234, 0.9876], [0.1234, 0.9876], 2.0)</code>应返回<code>Coincident point. Infinite solutions</code>'
|
||||
testString: assert.deepEqual(getCircles(...testCases[2]), answers[2]);
|
||||
- text: '<code>getCircles([0.1234, 0.9876], [0.8765, 0.2345], 0.5)</code>应返回<code>No intersection. Points further apart than circle diameter</code>'
|
||||
testString: assert.deepEqual(getCircles(...testCases[3]), answers[3]);
|
||||
- text: '<code>getCircles([0.1234, 0.9876], [0.1234, 0.9876], 0.0)</code>应返回<code>Radius Zero</code>'
|
||||
testString: assert.deepEqual(getCircles(...testCases[4]), answers[4]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function getCircles (...args) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,127 @@
|
||||
---
|
||||
title: Closest-pair problem
|
||||
id: 5951a53863c8a34f02bf1bdc
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 最近对的问题
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>提供一个函数来在二维中找到一组给定点中最接近的两个点,即求解平面情况下的<a href="https://en.wikipedia.org/wiki/Closest pair of points problem" title="wp:最近点的问题">最近点对问题</a> 。 </p><p>直接的解决方案是O(n <sup>2</sup> )算法(我们可以称之为强力算法);伪代码(使用索引)可以简单地: </p><pre> bruteForceClosestPair of P(1),P(2),... P(N)
|
||||
如果N <2那么
|
||||
返回∞
|
||||
其他
|
||||
minDistance←| P(1) - P(2)|
|
||||
minPoints←{P(1),P(2)}
|
||||
foreachi∈[1,N-1]
|
||||
foreachj∈[i + 1,N]
|
||||
if | P(i) - P(j)| <minDistance然后
|
||||
minDistance←| P(i) - P(j)|
|
||||
minPoints←{P(i),P(j)}
|
||||
万一
|
||||
ENDFOR
|
||||
ENDFOR
|
||||
return minDistance,minPoints
|
||||
万一
|
||||
</pre><p>一个更好的算法是基于递归分而治之的方法,正如<a href="https://en.wikipedia.org/wiki/Closest pair of points problem#Planar_case" title="wp:最近点的问题#Planar_case">维基百科最近的一对点问题</a>所解释的那样,即O(n log n);伪代码可以是: </p><pre>最近的(xP,yP)
|
||||
其中xP是P(1).. P(N)按x坐标排序,和
|
||||
yP是P(1).. P(N)按y坐标排序(升序)
|
||||
如果N≤3那么
|
||||
使用强力算法返回xP的最近点
|
||||
其他
|
||||
xL←xP点从1到⌈N/2⌉
|
||||
xR←xP点从⌈N/2⌉+ 1到N.
|
||||
xm←xP(⌈N/2⌉) <sub>x</sub>
|
||||
基←{P∈YP:P <sub>X≤XM}</sub>
|
||||
yR←{p∈yP:p <sub>x</sub> > xm}
|
||||
(dL,pairL)←nearestPair(xL,yL)
|
||||
(dR,pairR)←nearestRair(xR,yR)
|
||||
(dmin,pairMin)←(dR,pairR)
|
||||
如果dL <dR则
|
||||
(dmin,pairMin)←(dL,pairL)
|
||||
万一
|
||||
yS←{p∈yP:| xm - p <sub>x</sub> | <dmin}
|
||||
nS←yS中的点数
|
||||
(最近,最近的公里)←(dmin,pairMin)
|
||||
我从1到nS - 1
|
||||
k←i + 1
|
||||
而k≤nS和yS(k) <sub>y</sub> -yS(i) <sub>y</sub> <dmin
|
||||
if | yS(k) - yS(i)| <最接近的
|
||||
(最近,最近的公里)←(| yS(k) - yS(i)|,{yS(k),yS(i)})
|
||||
万一
|
||||
k←k + 1
|
||||
ENDWHILE
|
||||
ENDFOR
|
||||
返回最近,最近的
|
||||
万一
|
||||
</pre>参考和进一步阅读: <a href="https://en.wikipedia.org/wiki/Closest pair of points problem" title="wp:最近点的问题">最近的一对点问题</a> <a href="http://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html" title="链接:http://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html">最近的一对(麦吉尔)</a> <a href="http://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf" title="链接:http://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf">最近的一对(UCSB)</a> <a href="http://classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf" title="链接:http://classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf">最近的一对(WUStL)</a> <a href="http://www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt" title="链接:http://www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt">最近的一对(IUPUI)</a> <p>对于输入,期望参数是一个对象(点)数组,其中<code>x</code>和<code>y</code>成员设置为数字。对于输出,返回一个包含键的对象: <code>distance</code>和<code>pair</code>值对(即两对最近点的对)。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>getClosestPair</code>是一个函数。
|
||||
testString: assert(typeof getClosestPair === 'function');
|
||||
- text: 距离应如下。
|
||||
testString: assert.equal(getClosestPair(points1).distance, answer1.distance);
|
||||
- text: 要点应如下。
|
||||
testString: assert.deepEqual(JSON.parse(JSON.stringify(getClosestPair(points1))).pair, answer1.pair);
|
||||
- text: 距离应如下。
|
||||
testString: assert.equal(getClosestPair(points2).distance, answer2.distance);
|
||||
- text: 要点应如下。
|
||||
testString: assert.deepEqual(JSON.parse(JSON.stringify(getClosestPair(points2))).pair, answer2.pair);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
const Point = function (x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
};
|
||||
Point.prototype.getX = function () {
|
||||
return this.x;
|
||||
};
|
||||
Point.prototype.getY = function () {
|
||||
return this.y;
|
||||
};
|
||||
|
||||
function getClosestPair (pointsArr) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,75 @@
|
||||
---
|
||||
title: Combinations
|
||||
id: 5958469238c0d8d2632f46db
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 组合
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>给定非负整数<big>m</big>和<big>n</big> ,以排序顺序生成从<big>0</big> (零)到<big>n-1</big>的整数的所有大小<big>m个</big> <a href="http://mathworld.wolfram.com/Combination.html" title="链接:http://mathworld.wolfram.com/Combination.html">组合</a> (每个组合被排序并且整个表被排序)。 </p>例: <p> <big>3</big>梳子<big>5</big>是: </p><pre> 0 1 2
|
||||
0 1 3
|
||||
0 1 4
|
||||
0 2 3
|
||||
0 2 4
|
||||
0 3 4
|
||||
1 2 3
|
||||
1 2 4
|
||||
1 3 4
|
||||
2 3 4
|
||||
</pre></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>combinations</code>是一种功能。
|
||||
testString: assert(typeof combinations === 'function');
|
||||
- text: '<code>combinations(3, 5)</code>应返回<code>[[0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 2, 3], [0, 2, 4], [0, 3, 4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]</code> 。'
|
||||
testString: assert.deepEqual(combinations(testInput1[0], testInput1[1]), testOutput1);
|
||||
- text: '<code>combinations(4, 6)</code>应返回<code>[[0,1,2,3], [0,1,2,4], [0,1,2,5], [0,1,3,4], [0,1,3,5], [0,1,4,5], [0,2,3,4], [0,2,3,5], [0,2,4,5], [0,3,4,5], [1,2,3,4], [1,2,3,5], [1,2,4,5], [1,3,4,5], [2,3,4,5]]</code>'
|
||||
testString: assert.deepEqual(combinations(testInput2[0], testInput2[1]), testOutput2);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function combinations (m, n) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,71 @@
|
||||
---
|
||||
title: Comma quibbling
|
||||
id: 596e414344c3b2872167f0fe
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 逗号狡猾
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p> Comma quibbling是Eric Lippert在他的<a href="http://blogs.msdn.com/b/ericlippert/archive/2009/04/15/comma-quibbling.aspx" title="链接:http://blogs.msdn.com/b/ericlippert/archive/2009/04/15/comma-quibbling.aspx">博客中</a>最初设定的任务。 </p>任务: <p>编写一个函数来生成一个字符串输出,它是列表/序列中输入字的串联,其中: </p>没有单词的输入产生仅两个大括号字符“{}”的输出字符串。只有一个单词的输入,例如[“ABC”],会在两个大括号内产生单词的输出字符串,例如“{ABC}”。两个单词的输入,例如[“ABC”,“DEF”],产生两个大括号内的两个单词的输出字符串,其中单词由字符串“和”分隔,例如“{ABC和DEF}”。三个或更多单词的输入,例如[“ABC”,“DEF”,“G”,“H”],产生除了最后一个单词之外的所有输出字符串,用“,”分隔,最后一个单词用“和”分隔。 “并且都在括号内;例如“{ABC,DEF,G和H}”。 <p>在此页面上显示输出的以下一系列输入测试您的功能: </p> []#(无输入字)。 [“ABC”] [“ABC”,“DEF”] [“ABC”,“DEF”,“G”,“H”] <p>注意:假设此单词是此任务的非空字符串大写字符。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>quibble</code>是一种功能。
|
||||
testString: assert(typeof quibble === 'function');
|
||||
- text: <code>quibble(["ABC"])</code>应该返回一个字符串。
|
||||
testString: assert(typeof quibble(["ABC"]) === 'string');
|
||||
- text: <code>quibble([])</code>应返回“{}”。
|
||||
testString: assert.equal(quibble(testCases[0]), results[0]);
|
||||
- text: <code>quibble(["ABC"])</code>应该返回“{ABC}”。
|
||||
testString: assert.equal(quibble(testCases[1]), results[1]);
|
||||
- text: <code>quibble(["ABC", "DEF"])</code>应返回“{ABC和DEF}”。
|
||||
testString: assert.equal(quibble(testCases[2]), results[2]);
|
||||
- text: <code>quibble(["ABC", "DEF", "G", "H"])</code>应返回“{ABC,DEF,G和H}”。
|
||||
testString: assert.equal(quibble(testCases[3]), results[3]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function quibble (words) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,88 @@
|
||||
---
|
||||
title: Compare a list of strings
|
||||
id: 596e457071c35c882915b3e4
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 比较字符串列表
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>给定一个任意多个字符串的<a href="https://en.wikipedia.org/wiki/List_(abstract_data_type)" title="wp:List_(abstract_data_type)">列表</a> ,为以下每个条件实现一个函数: </p>测试它们是否都是词法上相等的测试,如果每个字符串在词法上小于它之后的字符串(即列表是否按严格的升序排列) </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>allEqual</code>是一个函数。
|
||||
testString: assert(typeof allEqual === 'function');
|
||||
- text: <code>azSorted</code>是一个函数。
|
||||
testString: assert(typeof azSorted === 'function');
|
||||
- text: <code>allEqual(["AA", "AA", "AA", "AA"])</code>返回true。
|
||||
testString: assert(allEqual(testCases[0]));
|
||||
- text: <code>azSorted(["AA", "AA", "AA", "AA"])</code>返回false。
|
||||
testString: assert(!azSorted(testCases[0]));
|
||||
- text: <code>allEqual(["AA", "ACB", "BB", "CC"])</code>返回false。
|
||||
testString: assert(!allEqual(testCases[1]));
|
||||
- text: <code>azSorted(["AA", "ACB", "BB", "CC"])</code>返回true。
|
||||
testString: assert(azSorted(testCases[1]));
|
||||
- text: <code>allEqual([])</code>返回true。
|
||||
testString: assert(allEqual(testCases[2]));
|
||||
- text: <code>azSorted([])</code>返回true。
|
||||
testString: assert(azSorted(testCases[2]));
|
||||
- text: <code>allEqual(["AA"])</code>返回true。
|
||||
testString: assert(allEqual(testCases[3]));
|
||||
- text: <code>azSorted(["AA"])</code>返回true。
|
||||
testString: assert(azSorted(testCases[3]));
|
||||
- text: <code>allEqual(["BB", "AA"])</code>返回false。
|
||||
testString: assert(!allEqual(testCases[4]));
|
||||
- text: <code>azSorted(["BB", "AA"])</code>返回false。
|
||||
testString: assert(!azSorted(testCases[4]));
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function allEqual (arr) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
function azSorted (arr) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
title: Convert seconds to compound duration
|
||||
id: 596fd036dc1ab896c5db98b1
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 将秒转换为复合持续时间
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>实现一个功能: </p>取一个表示以秒为单位的持续时间的正整数作为输入(例如, <code>100</code> ),并返回一个字符串,该字符串显示分解为周,日,小时,分钟和秒的相同持续时间,如下所述(例如,“ <code>1 min, 40 sec</code> “)。 <p>证明它通过以下三个测试用例: </p><p style="font-size:115%; margin:1em 0 0 0">测试用例</p><table><tbody><tr><th>输入号码</th><th>输出数量</th></tr><tr><td> 7259 </td><td> <code>2 hr, 59 sec</code> </td> </tr><tr><td> 86400 </td><td> <code>1 d</code> </td> </tr><tr><td> 6000000 </td><td> <code>9 wk, 6 d, 10 hr, 40 min</code> </td> </tr></tbody></table><p style="font-size:115%; margin:1em 0 0 0">细节</p>应使用以下五个单位: <table><tbody><tr><th>单元</th><th>输出中使用的后缀</th><th>转变</th></tr><tr><td>周</td><td> <code>wk</code> </td> <td> 1周= 7天</td></tr><tr><td>天</td><td> <code>d</code> </td> <td> 1天= 24小时</td></tr><tr><td>小时</td><td> <code>hr</code> </td> <td> 1小时= 60分钟</td></tr><tr><td>分钟</td><td> <code>min</code> </td> <td> 1分钟= 60秒</td></tr><tr><td>第二</td><td> <code>sec</code> </td> <td></td></tr></tbody></table>但是,仅包括输出中具有非零值的数量(例如,返回“ <code>1 d</code> ”而不是“ <code>0 wk, 1 d, 0 hr, 0 min, 0 sec</code> ”)。更大的单位优先于较小的单位尽可能(例如,返回<code>2 min, 10 sec</code>而不是<code>1 min, 70 sec</code>或<code>130 sec</code> )模拟测试用例中显示的格式(从最大单位到最小单位的数量,以逗号+空格分隔;数值和单位每个数量用空格分隔)。 <p></p><hr style="margin:1em 0;"><p></p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>convertSeconds</code>是一个函数。
|
||||
testString: assert(typeof convertSeconds === 'function');
|
||||
- text: '<code>convertSeconds(7259)</code>应该返回<code>2 hr, 59 sec</code> 。'
|
||||
testString: assert.equal(convertSeconds(testCases[0]), results[0]);
|
||||
- text: <code>convertSeconds(86400)</code>应返回<code>1 d</code> 。
|
||||
testString: assert.equal(convertSeconds(testCases[1]), results[1]);
|
||||
- text: '<code>convertSeconds(6000000)</code>应该返回<code>9 wk, 6 d, 10 hr, 40 min</code> 。'
|
||||
testString: assert.equal(convertSeconds(testCases[2]), results[2]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function convertSeconds (sec) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
title: Count occurrences of a substring
|
||||
id: 596fda99c69f779975a1b67d
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 计算子字符串的出现次数
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>创建函数或显示内置函数,以计算字符串中子字符串的非重叠出现次数。 </p><p>该函数应该有两个参数: </p>第一个参数是要搜索的字符串,第二个参数是要搜索的子字符串。 <p>它应该返回一个整数计数。 </p><p>匹配应产生最多数量的非重叠匹配。 </p><p>通常,这实质上意味着从左到右或从右到左匹配。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>countSubstring</code>是一个函数。
|
||||
testString: assert(typeof countSubstring === 'function');
|
||||
- text: <code>countSubstring("the three truths", "th")</code>应该返回<code>3</code> 。
|
||||
testString: assert.equal(countSubstring(testCases[0], searchString[0]), results[0]);
|
||||
- text: <code>countSubstring("ababababab", "abab")</code>应返回<code>2</code> 。
|
||||
testString: assert.equal(countSubstring(testCases[1], searchString[1]), results[1]);
|
||||
- text: <code>countSubstring("abaabba*bbaba*bbab", "a*b")</code>应返回<code>2</code> 。
|
||||
testString: assert.equal(countSubstring(testCases[2], searchString[2]), results[2]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function countSubstring (str, subStr) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,55 @@
|
||||
---
|
||||
title: Count the coins
|
||||
id: 59713bd26bdeb8a594fb9413
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 计算硬币
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p> <a href="https://en.wikipedia.org/wiki/United_States" title="链接:https://en.wikipedia.org/wiki/United_States">美国</a>货币有四种常见硬币: </p>季度(25美分)硬币(10美分)镍(5美分)和便士(1美分) <p>有六种方法可以换15美分: </p>一角钱和一角钱一角钱和5便士3镍2镍和5便士一镍和10便士15便士任务: <p>实现一个功能,以确定使用这些普通硬币改变一美元的方式有多少? (1美元= 100美分)。 </p>参考: <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_Temp_52" title="链接:http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_Temp_52">麻省理工学院出版社的算法</a> 。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>countCoins</code>是一个函数。
|
||||
testString: assert(typeof countCoins === 'function');
|
||||
- text: <code>countCoints()</code>应该返回242。
|
||||
testString: assert.equal(countCoins(), 242);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function countCoins () {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,65 @@
|
||||
---
|
||||
title: Cramer's rule
|
||||
id: 59713da0a428c1a62d7db430
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 克莱默的统治
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p> <a href="https://en.wikipedia.org/wiki/linear algebra" title="wp:线性代数">在线性代数中</a> , <a href="https://en.wikipedia.org/wiki/Cramer's rule" title="wp:Cramer的规则">Cramer规则</a>是一个<a href="https://en.wikipedia.org/wiki/system of linear equations" title="wp:线性方程组">线性方程组</a>解的显式公式,其中包含与未知数一样多的方程,只要系统具有唯一解,就有效。它通过用方程右边的矢量替换一列来表示(方形)系数矩阵的决定因素和从它获得的矩阵的解决方案。 </p><p>特定</p><p><big></big></p><p> <big>$ \ left \ {\ begin {matrix} a_1x + b_1y + c_1z&= {\ color {red} d_1} \\ a_2x + b_2y + c_2z&= {\ color {red} d_2} \\ a_3x + b_3y + c_3z&= {\颜色{红} D_3} \ {结束矩阵} \权。$</big> </p><p>以矩阵格式表示</p><p><big></big></p><p> <big>$ \ begin {bmatrix} a_1&b_1&c_1 \\ a_2&b_2&c_2 \\ a_3&b_3&c_3 \ end {bmatrix} \ begin {bmatrix} x \\ y \\ z \ end {bmatrix} = \ begin {bmatrix} {\ color {red} d_1} \\ {\ color {red} d_2} \\ {\ color {red} d_3} \ end {bmatrix}。$</big> </p><p>然后可以找到$ x,y $和$ z $的值,如下所示: </p><p><big></big></p><p> <big>$ x = \ frac {\ begin {vmatrix} {\ color {red} d_1}&b_1&c_1 \\ {\ color {red} d_2}&b_2&c_2 \\ {\ color {red} d_3}&b_3& c_3 \ end {vmatrix}} {\ begin {vmatrix} a_1&b_1&c_1 \\ a_2&b_2&c_2 \\ a_3&b_3&c_3 \ end {vmatrix}},\ quad y = \ frac {\ begin {vmatrix } a_1&{\ color {red} d_1}&c_1 \\ a_2&{\ color {red} d_2}&c_2 \\ a_3&{\ color {red} d_3}&c_3 \ end {vmatrix}} {\ begin {vmatrix} a_1&b_1&c_1 \\ a_2&b_2&c_2 \\ a_3&b_3&c_3 \ end {vmatrix}},\ text {和} z = \ frac {\ begin {vmatrix} a_1&b_1&{\ color {red} d_1} \\ a_2&b_2&{\ color {red} d_2} \\ a_3&b_3&{\ color {red} d_3} \ end {vmatrix}} {\ begin {vmatrix} a_1&b_1& c_1 \\ a_2&b_2&c_2 \\ a_3&b_3&c_3 \ end {vmatrix}}。$</big> </p>任务<p>给定以下方程组: </p><p> <big>$ \ begin {例} 2w-x + 5y + z = -3 \\ 3w + 2x + 2y-6z = -32 \\ w + 3x + 3y-z = -47 \\ 5w-2x-3y + 3z = 49 \\ \ end {cases} $</big> </p><p>使用Cramer的规则解决<big>$ w $,$ x $,$ y $</big>和<big>$ z $</big> 。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>cramersRule</code>是一个函数。
|
||||
testString: assert(typeof cramersRule === 'function');
|
||||
- text: '<code>cramersRule([[2, -1, 5, 1], [3, 2, 2, -6], [1, 3, 3, -1], [5, -2, -3, 3]], [-3, -32, -47, 49])</code>应返回<code>[2, -12, -4, 1]</code> 。'
|
||||
testString: assert.deepEqual(cramersRule(matrices[0], freeTerms[0]), answers[0]);
|
||||
- text: '<code>cramersRule([[3, 1, 1], [2, 2, 5], [1, -3, -4]], [3, -1, 2])</code>应返回<code>[1, 1, -1]</code> 。'
|
||||
testString: assert.deepEqual(cramersRule(matrices[1], freeTerms[1]), answers[1]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function cramersRule (matrix, freeTerms) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
title: Date format
|
||||
id: 59669d08d75b60482359409f
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 日期格式
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>返回包含以下格式的当前日期的数组: </p><p> - 2007-11-23和</p><p> - 2007年11月23日星期日</p><p>示例输出: <code>['2007-11-23', 'Sunday, November 23, 2007']</code> </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>getDateFormats</code>是一个函数。
|
||||
testString: assert(typeof getDateFormats === 'function');
|
||||
- text: 应该返回一个对象。
|
||||
testString: assert(typeof getDateFormats() === 'object');
|
||||
- text: 应该返回一个包含2个元素的数组。
|
||||
testString: assert(getDateFormats().length === 2);
|
||||
- text: 应以正确的格式返回正确的日期
|
||||
testString: assert.deepEqual(getDateFormats(), dates, equalsMessage);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function getDateFormats () {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,73 @@
|
||||
---
|
||||
title: Date manipulation
|
||||
id: 5966c21cf732a95f1b67dd28
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 日期操纵
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>给定EST中的日期字符串,将给定日期输出为字符串,并添加12小时。 </p><p>时区应该保留。 </p><p>示例输入: </p><p> <code>"March 7 2009 7:30pm EST"</code> </p> <p>输出示例: </p><p> <code>"March 8 2009 7:30am EST"</code> </p> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>add12Hours</code>是一个功能。
|
||||
testString: assert(typeof add12Hours === 'function');
|
||||
- text: <code>add12Hours(dateString)</code>应该返回一个字符串。
|
||||
testString: assert(typeof add12Hours('January 17 2017 11:43am EST') === 'string');
|
||||
- text: <code>add12Hours("" + tests[0] + "")</code>应该返回<code>"" + answers[0] + ""</code>
|
||||
testString: assert(add12Hours('January 17 2017 11:43am EST') === 'January 17 2017 11:43pm EST');
|
||||
- text: 汉德尔应该改变一天。 <code>add12Hours("" + tests[1] + "")</code>应返回<code>"" + answers[1] + ""</code>
|
||||
testString: assert(add12Hours('March 7 2009 7:30pm EST') === 'March 8 2009 7:30am EST');
|
||||
- text: 汉德尔月份应该在闰年中发生变化。 <code>add12Hours("" + tests[2] + "")</code>应返回<code>"" + answers[2] + ""</code>
|
||||
testString: assert(add12Hours('February 29 2004 9:15pm EST') === 'March 1 2004 9:15am EST');
|
||||
- text: 应该在一个共同的年份改变汉德尔月份。 <code>add12Hours("" + tests[3] + "")</code>应该返回<code>"" + answers[3] + ""</code>
|
||||
testString: assert(add12Hours('February 28 1999 3:15pm EST') === 'March 1 1999 3:15am EST');
|
||||
- text: 汉德尔应该改变一年。 <code>add12Hours("" + tests[4] + "")</code>应该返回<code>"" + answers[4] + ""</code>
|
||||
testString: assert(add12Hours('December 31 2020 1:45pm EST') === 'January 1 2021 1:45am EST');
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function add12Hours (dateString) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
title: Day of the week
|
||||
id: 5966f99c45e8976909a85575
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 一周中的天
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>一家公司决定,每当圣诞节落在星期天,他们将给予他们的工人所有额外带薪假期,这样,在任何公共假期,工人将不必在下一周(12月25日到1月1日之间)工作。 </p><p>任务: </p><p>编写一个开始年份和结束年份的函数,并返回12月25日为星期日的所有年份的数组。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>findXmasSunday</code>是一个函数。
|
||||
testString: assert(typeof findXmasSunday === 'function');
|
||||
- text: '<code>findChristmasSunday(2000, 2100)</code>应该返回一个数组。'
|
||||
testString: assert(typeof findXmasSunday(2000, 2100) === 'object');
|
||||
- text: '<code>findChristmasSunday(2008, 2121</code>应该回归[1977,1983,1988,1994,2005,2011,2016]'
|
||||
testString: assert.deepEqual(findXmasSunday(1970, 2017), firstSolution);
|
||||
- text: '<code>findChristmasSunday(2008, 2121</code>应该返回[2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118]'
|
||||
testString: assert.deepEqual(findXmasSunday(2008, 2121), secondSolution);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function findXmasSunday (start, end) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,91 @@
|
||||
---
|
||||
title: Deal cards for FreeCell
|
||||
id: 59694356a6e7011f7f1c5f4e
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: FreeCell的交易卡
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p> Free Cell是Paul Alfille在1978年向PLATO系统推出的单人纸牌游戏。微软的Jim Horne将名称更改为FreeCell并重新实现了<a href="http://rosettacode.org/wiki/DOS" title="DOS">DOS</a>游戏,然后是<a href="http://rosettacode.org/wiki/Windows" title="视窗">Windows</a>游戏。 </p><p>这个版本引入了32000个编号的交易。 ( <a href="http://www.solitairelaboratory.com/fcfaq.html" title="链接:http://www.solitairelaboratory.com/fcfaq.html">FreeCell FAQ</a>讲述了这段历史。) </p><p>随着游戏的流行,Jim Horne披露<a href="http://www.solitairelaboratory.com/mshuffle.txt" title="链接:http://www.solitairelaboratory.com/mshuffle.txt">了这种算法</a> ,FreeCell的其他实现开始重现微软的交易。 </p><p>这些交易编号从1到32000。 </p><p>微软的新版本有100万笔交易,编号从1到1000000;某些实现允许该范围之外的数字。 </p><p>该算法使用Microsoft C的这种<a href="http://rosettacode.org/wiki/linear congruential generator" title="线性同余发生器">线性同余生成器</a> : </p> $ state_ {n + 1} \ equiv 214013 \ times state_n + 2531011 \ pmod {2 ^ {31}} $ $ rand_n = state_n \ div 2 ^ {16} $ $ rand_n $的范围是0到32767。 <p>该算法如下: </p>使用交易编号为RNG播种。创建一个由52张牌组成的<a href="http://rosettacode.org/wiki/array" title="排列">阵列</a> :俱乐部的王牌,钻石王牌,心中的王牌,黑桃王牌,2个俱乐部,2个钻石等等等等:Ace,2,3,4,5,6, 7,8,9,10,杰克,女王,国王。数组索引为0到51,其中俱乐部的Ace为0,黑桃之王为51.直到数组为空:在索引≡下一个随机数(mod数组长度)中选择随机卡。将此随机卡与阵列的最后一张卡交换。从阵列中删除此随机卡。 (数组长度减少1.)处理此随机卡。交易所有52张牌,面朝上,横跨8列。前8张牌分为8列,后8张牌分为8张,依此类推。例: <p>订购交易卡</p><p></p><pre> 1 2 3 4 5 6 7 8
|
||||
9 10 11 12 13 14 15 16
|
||||
17 18 19 20 21 22 23 24
|
||||
25 26 27 28 29 30 31 32
|
||||
33 34 35 36 37 38 39 40
|
||||
41 42 43 44 45 46 47 48
|
||||
49 50 51 52 </pre><p></p><p>游戏#1 </p><p></p><pre> [
|
||||
['JD','2D','9H','JC','5D','7H','7C','5H'],
|
||||
['KD','KC','9S','5S','AD','QC','KH','3H'],
|
||||
['2S','KS','9D','QD','JS','AS','AH','3C'],
|
||||
['4C','5C','TS','QH','4H','AC','4D','7S'],
|
||||
['3S','TD','4S','TH','8H','2C','JH','7D'],
|
||||
['6D','8S','8D','QS','6C','3D','8C','TC'],
|
||||
['6S','9C','2H','6H']
|
||||
] </pre><p></p><p>游戏#617 </p><p></p><pre> [
|
||||
['7D','AD','5C','3S','5S','8C','2D','AH'],
|
||||
['TD','7S','QD','AC','6D','8H','AS','KH'],
|
||||
['TH','QC','3H','9D','6S','8D','3D','TC'],
|
||||
['KD','5H','9S','3C','8S','7H','4D','JS'],
|
||||
['4C','QS','9C','9H','7C','6H','2C','2S'],
|
||||
['4S','TS','2H','5D','JC','6C','JH','QH'],
|
||||
['JD','KS','KC','4H']
|
||||
] </pre><p></p>任务: <p>编写一个函数来获取交易编号并按照与此算法相同的顺序处理卡。 </p><p>该函数必须返回表示FreeCell板的二维数组。 </p><p>还可以针对<a href="http://freecellgamesolutions.com/" title="链接:http://freecellgamesolutions.com/">1000000游戏的FreeCell解决方案</a>检查交易。 </p><p> (召唤一个视频解决方案,它会显示初始交易。) </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>dealFreeCell</code>是一个功能。
|
||||
testString: assert(typeof dealFreeCell === 'function');
|
||||
- text: <code>dealFreeCell(seed)</code>应该返回一个对象。
|
||||
testString: assert(typeof dealFreeCell(1) === 'object');
|
||||
- text: <code>dealFreeCell(seed)</code>应该返回一个长度为7的数组。
|
||||
testString: assert(dealFreeCell(1).length === 7);
|
||||
- text: <code>dealFreeCell(1)</code>应该返回一个与示例“Game#1”相同的数组
|
||||
testString: "assert.deepEqual(dealFreeCell(1), game1);"
|
||||
- text: <code>dealFreeCell(617)</code>应该返回一个与示例“Game#617”相同的数组
|
||||
testString: "assert.deepEqual(dealFreeCell(617), game617);"
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function dealFreeCell (seed) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,69 @@
|
||||
---
|
||||
title: Deepcopy
|
||||
id: 596a8888ab7c01048de257d5
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: deepcopy的
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>编写一个返回给定对象的深层副本的函数。 </p><p>副本不得与给定的对象相同。 </p><p>此任务不会测试: </p>具有属性属性的对象Date对象或具有Date对象属性的对象RegEx或具有RegEx对象属性的对象原型复制</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>deepcopy</code>应该是一个功能。
|
||||
testString: assert(typeof deepcopy === 'function');
|
||||
- text: '<code>deepcopy({test: "test"})</code>应返回一个对象。'
|
||||
testString: 'assert(typeof deepcopy(obj1) === ''object'');'
|
||||
- text: 不应该返回提供的相同对象。
|
||||
testString: assert(deepcopy(obj2) != obj2);
|
||||
- text: 传递包含数组的对象时,应返回该对象的深层副本。
|
||||
testString: assert.deepEqual(deepcopy(obj2), obj2);
|
||||
- text: 传递包含另一个对象的对象时,应返回该对象的深层副本。
|
||||
testString: assert.deepEqual(deepcopy(obj3), obj3);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function deepcopy (obj) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,79 @@
|
||||
---
|
||||
title: Define a primitive data type
|
||||
id: 597089c87eec450c68aa1643
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 定义原始数据类型
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>定义一个行为类似于整数但最低有效值为1且最高有效值为10的类型。 </p>错误:如果您尝试实例化一个值超出1 - 10的<code>Num</code> ,它应该抛出一个错误消息为<code>'Out of range'</code>的<code>TypeError</code> 。如果您尝试使用不是<code>Num</code>的值实例化<code>Num</code> ,则应抛出<code>TypeError</code>并显示错误消息<code>'Not a Number'</code> 。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>Num</code>应该是一个功能。
|
||||
testString: assert(typeof Num === 'function');
|
||||
- text: <code>new Num(4)</code>应返回一个对象。
|
||||
testString: assert(typeof (new Num(4)) === 'object');
|
||||
- text: '<code>new Num(\'test\')</code>应抛出一个带有消息“非数字”的TypeError。'
|
||||
testString: assert.throws(() => new Num('test'), TypeError);
|
||||
- text: <code>new Num(0)</code>应该抛出一个带有消息“超出范围”的TypeError。
|
||||
testString: assert.throws(() => new Num(0), TypeError);
|
||||
- text: <code>new Num(-5)</code>应该抛出一个带有消息“超出范围”的TypeError。
|
||||
testString: assert.throws(() => new Num(-5), TypeError);
|
||||
- text: <code>new Num(10)</code>应抛出一个带有消息“超出范围”的TypeError。
|
||||
testString: assert.throws(() => new Num(11), TypeError);
|
||||
- text: <code>new Num(20)</code>应抛出一个带有消息“超出范围”的TypeError。
|
||||
testString: assert.throws(() => new Num(20), TypeError);
|
||||
- text: <code>new Num(3) + new Num(4)</code>应该等于7。
|
||||
testString: assert.equal(new Num(3) + new Num(4), 7);
|
||||
- text: <code>new Num(3) - new Num(4)</code>应该等于-1。
|
||||
testString: assert.equal(new Num(3) - new Num(4), -1);
|
||||
- text: <code>new Num(3) * new Num(4)</code>应该等于12。
|
||||
testString: assert.equal(new Num(3) * new Num(4), 12);
|
||||
- text: <code>new Num(3) / new Num(4)</code>应该等于0.75。
|
||||
testString: assert.equal(new Num(3) / new Num(4), 0.75);
|
||||
- text: <code>new Num(3) < new Num(4)</code>应该是真的。
|
||||
testString: assert(new Num(3) < new Num(4));
|
||||
- text: <code>new Num(3) > new Num(4)</code>应该是假的。
|
||||
testString: assert(!(new Num(3) > new Num(4)));
|
||||
- text: '<code>(new Num(5)).toString()</code>应返回\'5 \''
|
||||
testString: assert.equal((new Num(5)).toString(), '5');
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function Num (n) {
|
||||
// Good luck!
|
||||
return n;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
title: Department Numbers
|
||||
id: 59f40b17e79dbf1ab720ed7a
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 部门编号
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>有一个高度组织化的城市决定为每个部门分配一个号码: </p>警察局环卫部门消防部门<p>每个部门的数字可以在1到7之间(含)。 </p><p>这三个部门编号应该是唯一的(彼此不同),并且必须加起来为12。 </p><p>警察局长不喜欢奇怪的号码,并希望他的部门有一个偶数。 </p>任务: <p>编写一个输出所有有效组合的程序: </p><p> [2,3,7] </p><p> [2,4,6] </p><p> [2,6,4] </p><p> [2,7,3] </p><p> [4,1,7] </p><p> [4,2,6] </p><p> [4,3,5] </p><p> [4,5,3] </p><p> [4,6,2] </p><p> [4,7,1] </p><p> [6,1,5] </p><p> [6,2,4] </p><p> [6,4,2] </p><p> [6,5,1] </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>combinations</code>应该是一个功能。
|
||||
testString: assert(typeof combinations === 'function');
|
||||
- text: '<code>combinations([1, 2, 3], 6)</code>应该返回一个数组。'
|
||||
testString: assert(Array.isArray(combinations([1, 2, 3], 6)));
|
||||
- text: '<code>combinations([1, 2, 3, 4, 5, 6, 7], 12)</code>应返回长度为14的数组。'
|
||||
testString: assert(combinations(nums, total).length === len);
|
||||
- text: '<code>combinations([1, 2, 3, 4, 5, 6, 7], 12)</code>应返回所有有效组合。'
|
||||
testString: assert.deepEqual(combinations(nums, total), result);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function combinations (possibleNumbers, total) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
title: Discordian date
|
||||
id: 59f4eafba0343628bb682785
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: Discordian日期
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>将给定日期从<a href="https://en.wikipedia.org/wiki/Gregorian calendar" title="wp:阳历">公历</a>转换为<a href="https://en.wikipedia.org/wiki/Discordian calendar" title="wp:Discordian日历">Discordian日历</a> 。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>discordianDate</code>是一个函数。
|
||||
testString: assert(typeof discordianDate === 'function');
|
||||
- text: <code>discordianDate(new Date(2010, 6, 22))</code> <code>"Pungenday, the 57th day of Confusion in the YOLD 3176"</code> <code>discordianDate(new Date(2010, 6, 22))</code>应该返回<code>"Pungenday, the 57th day of Confusion in the YOLD 3176"</code> 。
|
||||
testString: assert(discordianDate(new Date(2010, 6, 22)) === 'Pungenday, the 57th day of Confusion in the YOLD 3176');
|
||||
- text: <code>discordianDate(new Date(2012, 1, 28))</code>应该返回<code>"Prickle-Prickle, the 59th day of Chaos in the YOLD 3178"</code> 。
|
||||
testString: assert(discordianDate(new Date(2012, 1, 28)) === 'Prickle-Prickle, the 59th day of Chaos in the YOLD 3178');
|
||||
- text: <code>discordianDate(new Date(2012, 1, 29))</code> <code>"Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib's Day!"</code> <code>discordianDate(new Date(2012, 1, 29))</code>应该返回<code>"Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib's Day!"</code> 。
|
||||
testString: assert(discordianDate(new Date(2012, 1, 29)) === 'Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib\'s Day!');
|
||||
- text: <code>discordianDate(new Date(2012, 2, 1))</code>应该返回<code>"Setting Orange, the 60th day of Chaos in the YOLD 3178"</code> 。
|
||||
testString: assert(discordianDate(new Date(2012, 2, 1)) === 'Setting Orange, the 60th day of Chaos in the YOLD 3178');
|
||||
- text: <code>discordianDate(new Date(2010, 0, 5))</code> <code>"Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!"</code> <code>discordianDate(new Date(2010, 0, 5))</code>应该返回<code>"Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!"</code> 。
|
||||
testString: assert(discordianDate(new Date(2010, 0, 5)) === 'Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!');
|
||||
- text: <code>discordianDate(new Date(2011, 4, 3))</code>应该返回<code>"Pungenday, the 50th day of Discord in the YOLD 3177. Celebrate Discoflux!"</code> 。
|
||||
testString: assert(discordianDate(new Date(2011, 4, 3)) === 'Pungenday, the 50th day of Discord in the YOLD 3177. Celebrate Discoflux!');
|
||||
- text: <code>discordianDate(new Date(2015, 9, 19))</code> <code>"Boomtime, the 73rd day of Bureaucracy in the YOLD 3181"</code> <code>discordianDate(new Date(2015, 9, 19))</code>应该返回<code>"Boomtime, the 73rd day of Bureaucracy in the YOLD 3181"</code> 。
|
||||
testString: assert(discordianDate(new Date(2015, 9, 19)) === 'Boomtime, the 73rd day of Bureaucracy in the YOLD 3181');
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function discordianDate (date) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,66 @@
|
||||
---
|
||||
title: Element-wise operations
|
||||
id: 599c333915e0ea32d04d4bec
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 元素操作
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>实现基本的元素矩阵 - 矩阵和标量矩阵运算。 </p><p>实行: </p><p> :: *另外</p><p> :: *减法</p><p> :: *乘法</p><p> :: *分裂</p><p> :: *取幂</p><p>第一个参数是要执行的操作,例如:用于矩阵加法的“m_add”和用于标量加法的“s_add”。第二和第三参数将是要在其上执行操作的矩阵。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>operation</code>是一种功能。
|
||||
testString: assert(typeof operation === 'function');
|
||||
- text: <code>operation("m_add",[[1,2],[3,4]],[[1,2],[3,4]])</code>应返回<code>[[2,4],[6,8]]</code> 。
|
||||
testString: assert.deepEqual(operation('m_add', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[2, 4], [6, 8]]);
|
||||
- text: <code>operation("s_add",[[1,2],[3,4]],[[1,2],[3,4]])</code>应返回<code>[[3,4],[5,6]]</code> 。
|
||||
testString: assert.deepEqual(operation('s_add', [[1, 2], [3, 4]], 2), [[3, 4], [5, 6]]);
|
||||
- text: <code>operation("m_sub",[[1,2],[3,4]],[[1,2],[3,4]])</code>应返回<code>[[0,0],[0,0]]</code> 。
|
||||
testString: assert.deepEqual(operation('m_sub', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[0, 0], [0, 0]]);
|
||||
- text: <code>operation("m_mult",[[1,2],[3,4]],[[1,2],[3,4]])</code>应该返回<code>[[1,4],[9,16]]</code> 。
|
||||
testString: assert.deepEqual(operation('m_mult', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 4], [9, 16]]);
|
||||
- text: <code>operation("m_div",[[1,2],[3,4]],[[1,2],[3,4]])</code>应返回<code>[[1,1],[1,1]]</code> 。
|
||||
testString: assert.deepEqual(operation('m_div', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 1], [1, 1]]);
|
||||
- text: <code>operation("m_exp",[[1,2],[3,4]],[[1,2],[3,4]])</code>应返回<code>[[1,4],[27,256]]</code> 。
|
||||
testString: assert.deepEqual(operation('m_exp', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 4], [27, 256]]);
|
||||
- text: <code>operation("m_add",[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]])</code>应该返回<code>[[10,12,14,16],[18,20,22,24]]</code> 。
|
||||
testString: assert.deepEqual(operation('m_add', [[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]), [[10, 12, 14, 16], [18, 20, 22, 24]]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function operation (op, arr1, arr2) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,60 @@
|
||||
---
|
||||
title: Emirp primes
|
||||
id: 599d0ba974141b0f508b37d5
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: Emirp奖金
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>一个emirp(向后拼写的主要拼写)是素数,当它们被反转时(在它们的十进制表示中)是一个不同的素数。 </p><p>编写应能功能:显示前<b>n</b> eprimes numbers.Show在range.Show的eprimes数字eprimes的在range.Show <b><sup>第</sup> n <sup>个</sup></b> eprimes数目。 </p><p>该函数应该有两个参数。第一个将接收<b>n</b>或作为数组的范围。第二个将接收一个布尔值,它指定函数是否将eprimes作为数组或单个数字(范围中的素数或第<b>n <sup>个</sup></b>素数)返回。根据参数,函数应返回数组或数字。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>emirps</code>是一个功能。
|
||||
testString: assert(typeof emirps === 'function');
|
||||
- text: '<code>emirps(20,true)</code>应该返回<code>[13,17,31,37,71,73,79,97,107,113,149,157,167,179,199,311,337,347,359,389]</code>'
|
||||
testString: assert.deepEqual(emirps(20, true), [13, 17, 31, 37, 71, 73, 79, 97, 107, 113, 149, 157, 167, 179, 199, 311, 337, 347, 359, 389]);
|
||||
- text: <code>emirps(10000)</code>应该返回<code>948349</code>
|
||||
testString: assert.deepEqual(emirps(1000), 70529);
|
||||
- text: '<code>emirps([7700,8000],true)</code>应该返回<code>[7717,7757,7817,7841,7867,7879,7901,7927,7949,7951,7963]</code>'
|
||||
testString: assert.deepEqual(emirps([7700, 8000], true), [7717, 7757, 7817, 7841, 7867, 7879, 7901, 7927, 7949, 7951, 7963]);
|
||||
- text: '<code>emirps([7700,8000],true)</code>应该返回<code>11</code>'
|
||||
testString: assert.deepEqual(emirps([7700, 8000], false), 11);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function emirps(n) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,64 @@
|
||||
---
|
||||
title: Entropy
|
||||
id: 599d15309e88c813a40baf58
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 熵
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>计算给定输入字符串的香农熵H. </p><p>给定谨慎的随机变量$ X $,它是$ N $“符号”(总字符)的字符串,由$ n $个不同的字符组成(对于二进制,n = 2),位/符号中X的香农熵是: </p><p> $ H_2(X)= - \ sum_ {i = 1} ^ n \ frac {count_i} {N} \ log_2 \ left(\ frac {count_i} {N} \ right)$ </p><p>其中$ count_i $是字符$ n_i $的计数。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>entropy</code>是一种功能。
|
||||
testString: assert(typeof entropy === 'function');
|
||||
- text: <code>entropy("0")</code>应该返回<code>0</code>
|
||||
testString: assert.equal(entropy('0'), 0);
|
||||
- text: <code>entropy("01")</code>应该返回<code>1</code>
|
||||
testString: assert.equal(entropy('01'), 1);
|
||||
- text: <code>entropy("0123")</code>应该返回<code>2</code>
|
||||
testString: assert.equal(entropy('0123'), 2);
|
||||
- text: <code>entropy("01234567")</code>应该返回<code>3</code>
|
||||
testString: assert.equal(entropy('01234567'), 3);
|
||||
- text: <code>entropy("0123456789abcdef")</code>应返回<code>4</code>
|
||||
testString: assert.equal(entropy('0123456789abcdef'), 4);
|
||||
- text: <code>entropy("1223334444")</code>应返回<code>1.8464393446710154</code>
|
||||
testString: assert.equal(entropy('1223334444'), 1.8464393446710154);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function entropy (s) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,72 @@
|
||||
---
|
||||
title: Equilibrium index
|
||||
id: 5987fd532b954e0f21b5d3f6
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 均衡指数
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>序列的平衡指数是序列的索引,使得较低指数处的元素之和等于较高指数处的元素之和。 </p><p>例如,在序列<big>$ A $中</big> : </p><p> :::: <big>$ A_0 = -7 $</big> </p><p> :::: <big>$ A_1 = 1 $</big> </p><p> :::: <big>$ A_2 = 5 $</big> </p><p> :::: <big>$ A_3 = 2 $</big> </p><p> :::: <big>$ A_4 = -4 $</big> </p><p> :::: <big>$ A_5 = 3 $</big> </p><p> :::: <big>$ A_6 = 0 $</big> </p><p> 3是均衡指数,因为: </p><p> :::: <big>$ A_0 + A_1 + A_2 = A_4 + A_5 + A_6 $</big> </p><p> 6也是均衡指数,因为: </p><p> :::: <big>$ A_0 + A_1 + A_2 + A_3 + A_4 + A_5 = 0 $</big> </p><p> (零元素之和为零) </p><p> 7不是均衡指数,因为它不是序列<big>$ A $</big>的有效索引。 </p><p>编写一个函数,给定一个序列,返回其平衡指数(如果有的话)。 </p><p>假设序列可能很长。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>equilibrium</code>是一种功能。
|
||||
testString: assert(typeof equilibrium === 'function');
|
||||
- text: '<code>equilibrium([-7, 1, 5, 2, -4, 3, 0])</code> <code>[3,6]</code> <code>equilibrium([-7, 1, 5, 2, -4, 3, 0])</code>应该返回<code>[3,6]</code> 。'
|
||||
testString: assert.deepEqual(equilibrium(equilibriumTests[0]), ans[0]);
|
||||
- text: '<code>equilibrium([2, 4, 6])</code>应该返回<code>[]</code> 。'
|
||||
testString: assert.deepEqual(equilibrium(equilibriumTests[1]), ans[1]);
|
||||
- text: '<code>equilibrium([2, 9, 2])</code>应该返回<code>[1]</code> 。'
|
||||
testString: assert.deepEqual(equilibrium(equilibriumTests[2]), ans[2]);
|
||||
- text: '<code>equilibrium([1, -1, 1, -1, 1, -1, 1])</code>应该返回<code>[0,1,2,3,4,5,6]</code> 。'
|
||||
testString: assert.deepEqual(equilibrium(equilibriumTests[3]), ans[3]);
|
||||
- text: '<code>equilibrium([1])</code>应该返回<code>[0]</code> 。'
|
||||
testString: assert.deepEqual(equilibrium(equilibriumTests[4]), ans[4]);
|
||||
- text: '<code>equilibrium([])</code>应该返回<code>[]</code> 。'
|
||||
testString: assert.deepEqual(equilibrium(equilibriumTests[5]), ans[5]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function equilibrium (a) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,62 @@
|
||||
---
|
||||
title: Ethiopian multiplication
|
||||
id: 599d1566a02b571412643b84
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 埃塞俄比亚的乘法
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>埃塞俄比亚乘法是一种仅使用加法,加倍和减半来乘以整数的方法。 </p><p>方法: </p>取两个数字相乘,然后将它们写在两列的顶部。在左侧列中反复将最后一个数字减半,丢弃任何余数,并将结果写入同一列中的最后一个,直到您写入值1.在右侧列中重复加倍最后一个数字并写入结果如下。在左侧列显示的同一行中添加结果时停止1.检查生成的表并丢弃左列中的值为偶数的任何行。将右侧列中的值相加,以产生将原始两个数相乘的结果<p>例如:17×34 </p><p> 17 34 </p><p>将第一列减半: </p><p> 17 34 </p><p> 8 </p><p> 4 </p><p> 2 </p><p> 1 </p><p>加倍第二列: </p><p> 17 34 </p><p> 8 68 </p><p> 4 136 </p><p> 2 272 </p><p> 1 544 </p><p>第一个单元格为偶数的删除行: </p><p> 17 34 </p><p> 8 <strike>68</strike> </p><p> 4 <strike>136</strike> </p><p> 2 <strike>272</strike> </p><p> 1 544 </p><p>将右侧列中的剩余数字相加: </p><p> 17 34 </p><p> 8 - </p><p> 4 --- </p><p> 2 --- </p><p> 1 544 </p><p> ==== </p><p> 578 </p><p>所以17乘以34,埃塞俄比亚方法是578。 </p>任务: <p>任务是定义三个命名函数/方法/过程/子例程: </p>一个将一个整数减半,一个减半整数,一个整数是偶数。 <p>使用这些函数创建一个执行埃塞俄比亚乘法的函数。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>eth_mult</code>是一个功能。
|
||||
testString: assert(typeof eth_mult === 'function');
|
||||
- text: '<code>eth_mult(17,34)</code>应该返回<code>578</code> 。'
|
||||
testString: assert.equal(eth_mult(17, 34), 578);
|
||||
- text: '<code>eth_mult(23,46)</code>应该返回<code>1058</code> 。'
|
||||
testString: assert.equal(eth_mult(23, 46), 1058);
|
||||
- text: '<code>eth_mult(12,27)</code>应该返回<code>324</code> 。'
|
||||
testString: assert.equal(eth_mult(12, 27), 324);
|
||||
- text: '<code>eth_mult(56,98)</code>应该返回<code>5488</code> 。'
|
||||
testString: assert.equal(eth_mult(56, 98), 5488);
|
||||
- text: '<code>eth_mult(63,74)</code>应该返回<code>4662</code> 。'
|
||||
testString: assert.equal(eth_mult(63, 74), 4662);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function eth_mult (a, b) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,60 @@
|
||||
---
|
||||
title: Euler method
|
||||
id: 59880443fb36441083c6c20e
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 欧拉方法
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>欧拉方法在数值上近似具有给定初始值的一阶常微分方程(ODE)的解。它是解决初始值问题(IVP)的一种显式方法,如<a href="https://en.wikipedia.org/wiki/Euler method" title="wp:欧拉方法">维基百科页面中所述</a> 。 </p><p> ODE必须以下列形式提供: </p><p> :: <big>$ \ frac {dy(t)} {dt} = f(t,y(t))$</big> </p><p>具有初始值</p><p> :: <big>$ y(t_0)= y_0 $</big> </p><p>为了得到数值解,我们用有限差分近似替换LHS上的导数: </p><p> :: <big>$ \ frac {dy(t)} {dt} \ approx \ frac {y(t + h)-y(t)} {h} $</big> </p><p>然后解决$ y(t + h)$: </p><p> :: <big>$ y(t + h)\ about y(t)+ h \,\ frac {dy(t)} {dt} $</big> </p><p>这是一样的</p><p> :: <big>$ y(t + h)\ about y(t)+ h \,f(t,y(t))$</big> </p><p>然后迭代解决方案规则是: </p><p> :: <big>$ y_ {n + 1} = y_n + h \,f(t_n,y_n)$</big> </p><p>其中<big>$ h $</big>是步长,是解决方案准确性最相关的参数。较小的步长会提高精度,但也会增加计算成本,因此必须根据手头的问题手工挑选。 </p><p>示例:牛顿冷却法</p><p> Newton的冷却定律描述了在温度<big>$ T_R $</big>的环境中初始温度<big>$ T(t_0)= T_0 $</big>的对象如何冷却: </p><p> :: <big>$ \ frac {dT(t)} {dt} = -k \,\ Delta T $</big> </p><p>要么</p><p> :: <big>$ \ frac {dT(t)} {dt} = -k \,(T(t) - T_R)$</big> </p><p>它表示物体的冷却速率<big>$ \ frac {dT(t)} {dt} $</big>与周围环境的当前温差<big>$ \ Delta T =(T(t) - T_R)$成正比</big> 。 </p><p>我们将与数值近似进行比较的解析解是</p><p> :: <big>$ T(t)= T_R +(T_0 - T_R)\; Ë^ { -克拉} $</big> </p>任务: <p>实现欧拉方法的一个例程,然后用它来解决牛顿冷却定律的给定例子,它有三种不同的步长: </p><p> :: * 2秒</p><p> :: * 5秒和</p><p> :: * 10秒</p><p>并与分析解决方案进行比较。 </p>初始值: <p> :: *初始温度<big>$ T_0 $</big>应为100°C </p><p> :: *室温<big>$ T_R $</big>应为20°C </p><p> :: *冷却常数<big>$ k $</big>应为0.07 </p><p> :: *计算的时间间隔应为0s──►100s </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>eulersMethod</code>是一个函数。
|
||||
testString: assert(typeof eulersMethod === 'function');
|
||||
- text: '<code>eulersMethod(0, 100, 100, 10)</code>应该返回一个数字。'
|
||||
testString: assert(typeof eulersMethod(0, 100, 100, 10) === 'number');
|
||||
- text: '<code>eulersMethod(0, 100, 100, 10)</code>应返回20.0424631833732。'
|
||||
testString: assert.equal(eulersMethod(0, 100, 100, 2), 20.0424631833732);
|
||||
- text: '<code>eulersMethod(0, 100, 100, 10)</code>应返回20.01449963666907。'
|
||||
testString: assert.equal(eulersMethod(0, 100, 100, 5), 20.01449963666907);
|
||||
- text: '<code>eulersMethod(0, 100, 100, 10)</code>应返回20.000472392。'
|
||||
testString: assert.equal(eulersMethod(0, 100, 100, 10), 20.000472392);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function eulersMethod (x1, y1, x2, h) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,62 @@
|
||||
---
|
||||
title: Evaluate binomial coefficients
|
||||
id: 598de241872ef8353c58a7a2
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 评估二项式系数
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>写一个函数来计算给定n和k值的二项式系数。 </p><p>推荐这个公式: </p> $ \ binom {n} {k} = \ frac {n!} {(nk)!k!} = \ frac {n(n-1)(n-2)\ ldots(n-k + 1)} { k(k-1)(k-2)\ ldots 1} $ </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>binom</code>是一个功能。
|
||||
testString: assert(typeof binom === 'function');
|
||||
- text: '<code>binom(5,3)</code>应该返回10。'
|
||||
testString: assert.equal(binom(5, 3), 10);
|
||||
- text: '<code>binom(7,2)</code>应该返回21。'
|
||||
testString: assert.equal(binom(7, 2), 21);
|
||||
- text: '<code>binom(10,4)</code>应该返回210。'
|
||||
testString: assert.equal(binom(10, 4), 210);
|
||||
- text: '<code>binom(6,1)</code>应该返回6。'
|
||||
testString: assert.equal(binom(6, 1), 6);
|
||||
- text: '<code>binom(12,8)</code>应该返回495。'
|
||||
testString: assert.equal(binom(12, 8), 495);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function binom (n, k) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,118 @@
|
||||
---
|
||||
title: Execute a Markov algorithm
|
||||
id: 59e09e6d412c5939baa02d16
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 执行马尔可夫算法
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>为<a href="https://en.wikipedia.org/wiki/Markov algorithm" title="wp:马尔可夫算法">马尔可夫算法</a>创建解释器。 </p><p>规则具有以下语法: </p><p><ruleset> :: =(( <comment> | <rule> ) <newline> +)* </newline></rule></comment></ruleset></p><p><comment> :: =#{ <any character=""> } </any></comment></p><p><rule> :: = <pattern><whitespace> - > <whitespace> [。] <replacement></replacement></whitespace></whitespace></pattern></rule></p><p><whitespace> :: =( <tab> | <space> )[ <whitespace> ] </whitespace></space></tab></whitespace></p><p>每行有一条规则。 </p><p>如果有的话<b>。</b> (期间)出席之前<replacement> ,那么这是一个终止规则,在这种情况下,解释器必须停止执行。 </replacement></p><p>规则集由一系列规则和可选注释组成。 </p><p> <big><big>规则集</big></big> </p><p>对条目使用以下测试: </p>规则集1: <pre>此规则文件是从Wikipedia中提取的:
|
||||
http://en.wikipedia.org/wiki/Markov_AlgorithmA - > apple
|
||||
B - >包
|
||||
S - >店
|
||||
T - >
|
||||
商店 - >我的兄弟
|
||||
一个从未使用过的 - >。终止规则
|
||||
</pre><p>示例文本: </p><p> <code>I bought a B of As from T S.</code> </p> <p>应该生成输出: </p><p> <code>I bought a bag of apples from my brother.</code> </p>规则集2: <p>终止规则的测试</p><pre>从维基百科的规则略有修改 - >苹果
|
||||
B - >包
|
||||
S - > .shop
|
||||
T - >
|
||||
商店 - >我的兄弟
|
||||
一个从未使用过的 - >。终止规则</pre><p>示例文本: </p><p> <code>I bought a B of As from T S.</code> </p> <p>应该生成: </p><p> <code>I bought a bag of apples from T shop.</code> </p>规则集3: <p>如果没有转义特殊的正则表达式字符,这将测试正确的替换顺序并可能捕获简单的基于正则表达式的替换例程。 </p><pre> BNF语法测试规则A - > apple
|
||||
WWWW - >用
|
||||
行李 - > - >。*
|
||||
B - >包
|
||||
- >。* - >钱
|
||||
W - > WW
|
||||
S - > .shop
|
||||
T - >
|
||||
商店 - >我的兄弟
|
||||
一个从未使用过的 - >。终止规则
|
||||
</pre><p>示例文本: </p><p> <code>I bought a B of As W my Bgage from T S.</code> </p> <p>应该生成: </p><p> <code>I bought a bag of apples with my money from T shop.</code> </p>规则集4: <p>这将测试规则扫描的正确顺序,并可能捕获以错误顺序扫描的替换例程。它实现了一般的一元乘法引擎。 (请注意,在此实现中,输入表达式必须放在下划线中。) </p><pre> ##一元乘法引擎,用于测试马尔可夫算法实现
|
||||
## Donal Fellows。
|
||||
一元加法引擎_ + 1 - > _1 +
|
||||
1 + 1 - > 11+
|
||||
通过将乘法的分裂转换为普通的
|
||||
addition1! - >!1
|
||||
,! - >!+
|
||||
_! - > _
|
||||
通过复制左侧,右侧乘以1 * 1 - > x,@ y进行一元乘法
|
||||
1x - > xX
|
||||
X, - > 1,1
|
||||
X1 - > 1X
|
||||
_x - > _X
|
||||
,x - >,X
|
||||
y1 - > 1y
|
||||
y_ - > _
|
||||
apply1 @ 1 - > x,@ y的下一阶段
|
||||
1 @ _ - > @_
|
||||
,@ _ - >!_
|
||||
++ - > +
|
||||
添加终止清除_1 - > 1
|
||||
1 + _ - > 1
|
||||
_ + _ - >
|
||||
</pre><p>示例文本: </p><p> <code>_1111*11111_</code> </p> <p>应该生成输出: </p><p> <code>11111111111111111111</code> </p>规则集5: <p>一台简单的<a href="http://en.wikipedia.org/wiki/Turing_machine" title="链接:http://en.wikipedia.org/wiki/Turing_machine">图灵机</a> , </p><p>实施三态<a href="http://en.wikipedia.org/wiki/Busy_beaver" title="链接:http://en.wikipedia.org/wiki/Busy_beaver">繁忙的海狸</a> 。 </p><p>磁带由0和1组成,状态为A,B,C和H(对于Halt),并且通过在头部所在的字符之前写入状态字母来指示磁头位置。 </p><p>必须在输入中给出机器操作的初始磁带的所有部分。 </p><p>除了证明Markov算法是Turing-complete之外,它还让我抓住了C ++实现中的一个错误,这个错误没有被前四个规则集捕获。 </p><pre>图灵机:三态繁忙的海狸
|
||||
#sta A,符号0 =>写1,向右移动,新状态BA0 - > 1B
|
||||
状态A,符号1 =>写1,向左移动,新状态C0A1 - > C01
|
||||
1A1 - > C11
|
||||
状态B,符号0 =>写1,向左移动,新状态A0B0 - > A01
|
||||
1B0 - > A11
|
||||
状态B,符号1 =>写1,向右移动,新状态BB1 - > 1B
|
||||
状态C,符号0 =>写1,向左移动,新状态B0C0 - > B01
|
||||
1C0 - > B11
|
||||
状态C,符号1 =>写1,向左移动,停止0C1 - > H01
|
||||
1C1 - > H11
|
||||
</pre><p>这个规则集应该转向</p><p> <code>000000A000000</code> </p> <p>成</p><p> <code>00011H1111000</code> </p> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>markov</code>是一个功能。
|
||||
testString: assert(typeof markov === 'function');
|
||||
- text: <code>markov(["A -> apple","B -> bag","S -> shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")</code>应该回复“我从我兄弟那里买了一袋苹果”。
|
||||
testString: assert.deepEqual(markov(rules[0],tests[0]),outputs[0]);
|
||||
- text: <code>markov(["A -> apple","B -> bag","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")</code>应该回来“我从T商店买了一袋苹果。”
|
||||
testString: assert.deepEqual(markov(rules[1],tests[1]),outputs[1]);
|
||||
- text: <code>markov(["A -> apple","WWWW -> with","Bgage -> ->.*","B -> bag","->.* -> money","W -> WW","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As W my Bgage from T S.")</code>应该返回”我从T商店用我的钱买了一袋苹果。“
|
||||
testString: assert.deepEqual(markov(rules[2],tests[2]),outputs[2]);
|
||||
- text: <code>markov(["_+1 -> _1+","1+1 -> 11+","1! -> !1",",! -> !+","_! -> _","1*1 -> x,@y","1x -> xX","X, -> 1,1","X1 -> 1X","_x -> _X",",x -> ,X","y1 -> 1y","y_ -> _","1@1 -> x,@y","1@_ -> @_",",@_ -> !_","++ -> +","_1 -> 1","1+_ -> 1","_+_ -> "],"_1111*11111_")</code>应返回”11111111111111111111“。
|
||||
testString: assert.deepEqual(markov(rules[3],tests[3]),outputs[3]);
|
||||
- text: <code>markov(["A0 -> 1B","0A1 -> C01","1A1 -> C11","0B0 -> A01","1B0 -> A11","B1 -> 1B","0C0 -> B01","1C0 -> B11","0C1 -> H01","1C1 -> H11"],"")</code>应返回”00011H1111000“。
|
||||
testString: assert.deepEqual(markov(rules[4],tests[4]),outputs[4]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function markov (rules,test) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,133 @@
|
||||
---
|
||||
title: Execute Brain****
|
||||
id: 59e0a8df964e4540d5abe599
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 执行大脑****
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>编写一个函数来实现Brain ****解释器。该函数将字符串作为参数,并应返回一个字符串作为输出。更多细节如下: </p><p> <a href="http://rosettacode.org/wiki/Brainf***" title="Brainf ***">RCBF</a>是一套为各种语言的Rosetta Code编写的<a href="http://rosettacode.org/wiki/Brainf***" title="Brainf ***">Brainf ***</a>编译器和解释器。 </p><p>以下是RCBF每个版本的链接。 </p><p>实现只需要正确实现以下指令: </p><p> {| </p><p> !命令</p><p> !描述</p><p> | - </p><p> |风格=“文本对齐:中心” | <code>></code> ||将指针向右移动</p><p> | - </p><p> |风格=“文本对齐:中心” | <code><</code> ||将指针移到左侧</p><p> | - </p><p> |风格=“文本对齐:中心” | <code>+</code> ||增加指针下的内存单元格</p><p> | - </p><p> |风格=“文本对齐:中心” | <code>-</code> ||减少指针下的内存单元格</p><p> | - </p><p> |风格=“文本对齐:中心” | <code>.</code> ||输出指针处单元格表示的字符</p><p> | - </p><p> |风格=“文本对齐:中心” | <code>,</code> ||输入一个字符并将其存储在指针的单元格中</p><p> | - </p><p> |风格=“文本对齐:中心” | <code>[</code> ||如果指针下的单元格为0,则跳过匹配<code>]</code> </p><p> | - </p><p> |风格=“文本对齐:中心” | <code>]</code> ||跳回匹配<code>[</code>如果指针下的单元格非零</p><p> |} </p><p>允许任何单元格大小,EOF( <u>E</u> nd- <u>O</u> - <u>F</u> ile)支持是可选的,无论您是否有有界或无界内存。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>brain(bye)</code>应该重新调整一个字符串
|
||||
testString: assert(typeof brain(bye) === 'string');
|
||||
- text: <code>brain("++++++[>++++++++++<-]>+++++.")</code should return "A"
|
||||
testString: assert.equal(brain("++++++[>++++++++++<-]>+++++."),"A");
|
||||
- text: <code>brain(bye)</code>应该回归<code>Goodbye, World!\\r\\n</code>
|
||||
testString: assert.equal(brain(bye), 'Goodbye, World!\r\n');
|
||||
- text: <code>brain(hello)</code>应该回归<code>Hello World!\\n</code>
|
||||
testString: assert.equal(brain(hello), "Hello World!\n");
|
||||
- text: <code>brain(fib)</code>应该返回<code>1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89</code>
|
||||
testString: assert.equal(brain(fib), "1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89");
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function brain (prog) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
### Before Test
|
||||
<div id='js-setup'>
|
||||
|
||||
```js
|
||||
let fib=`+
|
||||
|
||||
++
|
||||
|
||||
+++
|
||||
|
||||
++++
|
||||
|
||||
+>+>>
|
||||
|
||||
>>++++
|
||||
|
||||
+++++++
|
||||
|
||||
++++++++
|
||||
|
||||
+++++++++
|
||||
|
||||
++++++++++
|
||||
|
||||
++++++>++++
|
||||
|
||||
++++++++++++
|
||||
|
||||
+++++++++++++
|
||||
|
||||
+++<<<<<<[>[>>
|
||||
|
||||
>>>>+>+<<<<<<<-
|
||||
|
||||
]>>>>>>>[<<<<<<<
|
||||
|
||||
+>>>>>>>-]<[>++++
|
||||
|
||||
++++++[-<-[>>+>+<<
|
||||
|
||||
<-]>>>[<<<+>>>-]+<[
|
||||
|
||||
>[-]<[-]]>[<<[>>>+<<
|
||||
|
||||
<-]>>[-]]<<]>>>[>>+>+
|
||||
|
||||
<<<-]>>>[<<<+>>>-]+<[>
|
||||
|
||||
[-]<[-]]>[<<+>>[-]]<<<<
|
||||
|
||||
<<<]>>>>>[++++++++++++++
|
||||
|
||||
+++++++++++++++++++++++++
|
||||
|
||||
+++++++++.[-]]++++++++++<[
|
||||
|
||||
->-<]>+++++++++++++++++++++
|
||||
|
||||
+++++++++++++++++++++++++++.
|
||||
|
||||
[-]<<<<<<<<<<<<[>>>+>+<<<<-]>
|
||||
|
||||
>>>[<<<<+>>>>-]<-[>>.>.<<<[-]]
|
||||
|
||||
<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+
|
||||
|
||||
>-]>[<+>-]<<<-]`;
|
||||
let hello='++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'
|
||||
let bye='++++++++++[>+>+++>++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++>++++++++++++<<<<<<<<<-]>>>>+.>>>>+..<.<++++++++.>>>+.<<+.<<<<++++.<++.>>>+++++++.>>>.+++.<+++++++.--------.<<<<<+.<+++.---.';
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,60 @@
|
||||
---
|
||||
title: Extensible prime generator
|
||||
id: 598ee8b91b410510ae82efef
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 可扩展的素发生器
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>按顺序编写素数生成器,它将自动调整以适应任何合理高素数的生成。 </p>发电机应能:显示前<b>N个</b>黄金numbers.Show在range.Show的素数的素数在range.Show数<b><sup>第</sup> n <sup>个</sup></b>素数。 <p>该函数应该有两个参数。第一个将接收<b>n</b>或作为数组的范围。第二个将接收一个布尔值,它指定函数是否将素数作为数组或单个数字(范围中的素数或第<b>n <sup>个</sup></b>素数)返回。根据参数,函数应该返回一个数组。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>primeGenerator</code>是一个函数。
|
||||
testString: assert(typeof primeGenerator === 'function');
|
||||
- text: <code>primeGenerator</code>是一个函数。
|
||||
testString: assert.deepEqual(primeGenerator(20, true), [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]);
|
||||
- text: <code>primeGenerator</code>是一个函数。
|
||||
testString: assert.deepEqual(primeGenerator([100, 150], true), [101, 103, 107, 109, 113, 127, 131, 137, 139, 149]);
|
||||
- text: <code>primeGenerator</code>是一个函数。
|
||||
testString: assert.equal(primeGenerator([7700, 8000], false), 30);
|
||||
- text: <code>primeGenerator</code>是一个函数。
|
||||
testString: assert.equal(primeGenerator(10000, false), 104729);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function primeGenerator (num, showPrimes) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,68 @@
|
||||
---
|
||||
title: Factorial
|
||||
id: 597b2b2a2702b44414742771
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 阶乘
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>编写一个函数来返回一个数字的阶乘。 </p><p>一个数字的因子由下式给出: </p> N! = n *(n-1)*(n-2)* ..... * 1 <p>例如:3! = 3 * 2 * 1 = 6 4! = 4 * 3 * 2 * 1 = 24 </p><p>注意:0! = 1 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>factorial</code>是一种功能。
|
||||
testString: assert(typeof factorial === 'function');
|
||||
- text: <code>factorial(2)</code>应该返回一个数字。
|
||||
testString: assert(typeof factorial(2) === 'number');
|
||||
- text: <code>factorial(3)</code>应该返回6.“)
|
||||
testString: assert.equal(factorial(3), 6);
|
||||
- text: <code>factorial(3)</code>应返回120.“)
|
||||
testString: assert.equal(factorial(5), 120);
|
||||
- text: '<code>factorial(3)</code>应返回3,628,800。“)'
|
||||
testString: assert.equal(factorial(10), 3628800);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function factorial (n) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,60 @@
|
||||
---
|
||||
title: Factors of a Mersenne number
|
||||
id: 598eea87e5cf4b116c3ff81a
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 梅森数的因素
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>梅森数是2 <sup>P</sup> -1形式的数字。 </p><p>如果P是素数,那么梅森数可能是梅森素数</p><p> (如果P不是素数,则梅森数也不是素数)。 </p><p>在搜索梅森素数时,通过在开始可能冗长的<a href="http://rosettacode.org/wiki/Lucas-Lehmer test" title="Lucas-Lehmer测试">Lucas-Lehmer检验</a>之前找到一个小因子来消除指数是有利的。 </p><p>有非常有效的算法来确定数字是否除以2 <sup>P</sup> -1(或等效地,如果2 <sup>P</sup> mod(数字)= 1)。 </p><p>有些语言已经有了这个exponent-and-mod操作的内置实现(称为modPow或类似的)。 </p><p>以下是如何自己实现这个modPow: </p><p>例如,让我们计算2 <sup>23</sup> mod 47。 </p><p>将指数23转换为二进制,得到10111.从<tt>square</tt> = 1开始,重复平方。 </p><p>卸下指数的最高位,并且如果它是1 <tt>平方</tt>乘以由所述幂(2)的基础上,然后计算<tt>平方</tt>模47。 </p><p>在下一步中使用最后一步的模数结果作为<tt>square</tt>的初始值: </p><p>删除可选</p><p>方形顶部位乘以2 mod 47 </p><p> ------------ ------- ------------- ------ </p><p> 1 * 1 = 1 1 0111 1 * 2 = 2 2 </p><p> 2 * 2 = 4 0 111否4 </p><p> 4 * 4 = 16 1 11 16 * 2 = 32 32 </p><p> 32 * 32 = 1024 1 1 1024 * 2 = 2048 27 </p><p> 27 * 27 = 729 1 729 * 2 = 1458 1 </p><p>由于2 <sup>23</sup> mod 47 = 1,47是2 <sup>P</sup> -1的因子。 </p><p> (要看到这一点,从两边减去1:2 <sup>23</sup> -1 = 0 mod 47.) </p><p>由于我们已经证明47是一个因子,因此2 <sup>23</sup> -1不是素数。 </p><p> Mersenne数字的其他属性使我们能够进一步完善这一过程。 </p><p>任何因子q为2 <sup>P</sup> -1必须是2kP + 1的形式,k是正整数或零。此外,q必须是1或7 mod 8。 </p><p>最后任何潜在因素q必须是<a href="http://rosettacode.org/wiki/Primality by Trial Division" title="审判分庭的原始性">素数</a> 。 </p><p>与其他试验划分算法一样,算法在2kP + 1> sqrt(N)时停止。 </p><p>这些素性测试仅适用于P为素数的Mersenne数。例如,M <sub>4</sub> = 15不使用这些技术产生因子,而是产生3和5的因子,两者都不符合2kP + 1。 </p>任务: <p>使用上述方法找到因子2 <sup>929</sup> -1(又名M929) </p>相关任务: <a href="http://rosettacode.org/wiki/count in factors" title="算上因素">计数因素</a> <a href="http://rosettacode.org/wiki/prime decomposition" title="主要分解">素数分解</a> <a href="http://rosettacode.org/wiki/factors of an integer" title="整数的因子">的整数的因素</a> <a href="http://rosettacode.org/wiki/Sieve of Eratosthenes" title="Eratosthenes的筛子">埃拉托塞尼的筛</a> <a href="http://rosettacode.org/wiki/primality by trial division" title="审判分裂的素性">通过试验除法素性</a> <a href="http://rosettacode.org/wiki/trial factoring of a Mersenne number" title="试用Mensenne数的因式">梅森数的试验理</a> <a href="http://rosettacode.org/wiki/partition an integer X into N primes" title="将整数X划分为N个素数">分区的整数X为N个素数</a> <a href="http://rosettacode.org/wiki/sequence of primes by Trial Division" title="审判分庭的素数序列">由审判庭素数的序列</a> <a href="https://www.youtube.com/watch?v=SNwvJ7psoow" title="链接:https://www.youtube.com/watch?v = SNwvJ7psoow">在1948年计算机:2¹²⁷-1</a> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>check_mersenne</code>是一个函数。
|
||||
testString: assert(typeof check_mersenne === 'function');
|
||||
- text: <code>check_mersenne(3)</code>应该返回一个字符串。
|
||||
testString: assert(typeof check_mersenne(3) == 'string');
|
||||
- text: <code>check_mersenne(3)</code>应该返回“M3 = 2 ^ 3-1是素数”。
|
||||
testString: assert.equal(check_mersenne(3),"M3 = 2^3-1 is prime");
|
||||
- text: <code>check_mersenne(23)</code>应返回“M23 = 2 ^ 23-1与因子47复合”。
|
||||
testString: assert.equal(check_mersenne(23),"M23 = 2^23-1 is composite with factor 47");
|
||||
- text: <code>check_mersenne(929)</code>应返回“M929 = 2 ^ 929-1与因子13007复合
|
||||
testString: assert.equal(check_mersenne(929),"M929 = 2^929-1 is composite with factor 13007");
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function check_mersenne (p) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,66 @@
|
||||
---
|
||||
title: Factors of an integer
|
||||
id: 597f1e7fbc206f0e9ba95dc4
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 整数因子
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>编写一个返回正整数因子的函数。 </p><p>这些因子是正整数,通过该正整数可以将被分解的数量除以产生正整数结果。 </p> /// </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>factors</code>是一种功能。
|
||||
testString: assert(typeof factors === 'function');
|
||||
- text: '<code>factors(45)</code>应该返回<code>[1,3,5,9,15,45]</code> 。'
|
||||
testString: assert.deepEqual(factors(45), ans[0]);
|
||||
- text: '<code>factors(53)</code>应该返回<code>[1,53]</code> 。'
|
||||
testString: assert.deepEqual(factors(53), ans[1]);
|
||||
- text: '<code>factors(64)</code>应该返回<code>[1,2,4,8,16,32,64]</code> 。'
|
||||
testString: assert.deepEqual(factors(64), ans[2]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function factors (num) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,60 @@
|
||||
---
|
||||
title: Farey sequence
|
||||
id: 59c3ec9f15068017c96eb8a3
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: Farey序列
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>编写一个返回n阶Farey序列的函数。该函数应该有一个参数n。它应该将序列作为数组返回。阅读以下内容了解更多详情: </p><p>阶数n的<a href="https://en.wikipedia.org/wiki/Farey sequence" title="wp:Farey序列">Farey序列</a> F <sub>n</sub>是在0和1之间的完全减少的分数的序列,当在最低阶段时,具有小于或等于n的分母,按照增大的大小排列。 </p><p> Farey序列有时被错误地称为Farey系列。 </p><p>每个Farey序列: </p><p> :: *以值0开头,由分数$ \ frac {0} {1} $表示</p><p> :: *以值1结尾,由$ \ frac {1} {1} $分数表示。 </p><p>订单1到5的Farey序列是: </p><p> $ {\ bf \ it {F}} _ 1 = \ frac {0} {1},\ frac {1} {1} $ </p><p></p><p> $ {\ bf \ it {F}} _ 2 = \ frac {0} {1},\ frac {1} {2},\ frac {1} {1} $ </p><p></p><p> $ {\ bf \ it {F}} _ 3 = \ frac {0} {1},\ frac {1} {3},\ frac {1} {2},\ frac {2} {3},\ frac {1} {1} $ </p><p></p><p> $ {\ bf \ it {F}} _ 4 = \ frac {0} {1},\ frac {1} {4},\ frac {1} {3},\ frac {1} {2},\ frac {2} {3},\ frac {3} {4},\ frac {1} {1} $ </p><p></p><p> $ {\ bf \ it {F}} _ 5 = \ frac {0} {1},\ frac {1} {5},\ frac {1} {4},\ frac {1} {3},\ frac {2} {5},\ frac {1} {2},\ frac {3} {5},\ frac {2} {3},\ frac {3} {4},\ frac {4} {5 },\ frac {1} {1} $ </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>farey</code>是一种功能。
|
||||
testString: assert(typeof farey === 'function');
|
||||
- text: <code>farey(3)</code>应该返回一个数组
|
||||
testString: assert(Array.isArray(farey(3)));
|
||||
- text: <code>farey(3)</code>应该返回<code>["1/3","1/2","2/3"]</code>
|
||||
testString: assert.deepEqual(farey(3), ["1/3","1/2","2/3"]);
|
||||
- text: <code>farey(4)</code>应该返回<code>["1/4","1/3","1/2","2/4","2/3","3/4"]</code>
|
||||
testString: assert.deepEqual(farey(4), ["1/4","1/3","1/2","2/4","2/3","3/4"]);
|
||||
- text: <code>farey(5)</code>应返回<code>["1/5","1/4","1/3","2/5","1/2","2/4","3/5","2/3","3/4","4/5"]</code>
|
||||
testString: assert.deepEqual(farey(5), ["1/5","1/4","1/3","2/5","1/2","2/4","3/5","2/3","3/4","4/5"]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function farey (n) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,74 @@
|
||||
---
|
||||
title: Fibonacci n-step number sequences
|
||||
id: 598eef80ba501f1268170e1e
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 斐波那契n步数序列
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>编写一个函数来生成Fibonacci n步数序列和Lucas序列。第一个参数是n。第二个参数是要返回的元素数。第三个参数将指定是输出Fibonacci序列还是Lucas序列。如果参数为“f”,则返回Fibonacci序列,如果为“l”,则返回Lucas序列。序列必须作为数组返回。更多细节如下: </p><p>这些数字序列是普通<a href="http://rosettacode.org/wiki/Fibonacci sequence" title="斐波那契序列">斐波纳契数列</a>的扩展,其中: </p>对于$ n = 2 $,我们有Fibonacci序列;初始值$ [1,1] $和$ F_k ^ 2 = F_ {k-1} ^ 2 + F_ {k-2} ^ 2 $对于$ n = 3 $,我们有tribonacci序列;初始值$ [1,1,2] $和$ F_k ^ 3 = F_ {k-1} ^ 3 + F_ {k-2} ^ 3 + F_ {k-3} ^ 3 $ $ $ = 4 $我们有tetranacci序列;初始值$ [1,1,2,4] $和$ F_k ^ 4 = F_ {k-1} ^ 4 + F_ {k-2} ^ 4 + F_ {k-3} ^ 4 + F_ {k -4} ^ 4 $ ...对于一般的$ n> 2 $,我们有斐波那契$ n $ -step序列 - $ F_k ^ n $; $(n-1)$'斐波那契$ n $ -step序列$ F_k ^ {n-1} $的前$ n $值的初始值;和$ k $'这个$ n $'序列的值是$ F_k ^ n = \ sum_ {i = 1} ^ {(n)} {F_ {ki} ^ {(n)}} $ <p>对于$ n $的小值, <a href="https://en.wikipedia.org/wiki/Number prefix#Greek_series" title="wp:数字前缀#Greek_series">希腊数字前缀</a>有时用于单独命名每个系列。 </p><p> {| style =“text-align:left;” border =“4”cellpadding =“2”cellspacing =“2” </p><p> | + Fibonacci $ n $ -step序列</p><p> | - style =“background-color:rgb(255,204,255);” </p><p> ! $ n $ !!系列名称!!值</p><p> | - </p><p> | 2 ||斐波那契|| 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ...... </p><p> | - </p><p> | 3 || tribonacci || 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 ...... </p><p> | - </p><p> | 4 || tetranacci || 1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536 ...... </p><p> | - </p><p> | 5 || pentanacci || 1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930 ...... </p><p> | - </p><p> | 6 || hexanacci || 1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617 ...... </p><p> | - </p><p> | 7 || heptanacci || 1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936 ...... </p><p> | - </p><p> | 8 || octonacci || 1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080 ... </p><p> | - </p><p> | 9 || nonanacci || 1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144 ...... </p><p> | - </p><p> | 10 || decanacci || 1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172 ... </p><p> |} </p><p>可以在更改初始值的位置生成联合序列: </p><p> <a href="https://en.wikipedia.org/wiki/Lucas number" title="wp:卢卡斯号码">Lucas系列</a>将两个前面的值相加,例如$ n = 2 $的斐波那契数列,但使用$ [2,1] $作为其初始值。 </p><p><!-- Lucas numbers, Lucas number, Lucas series [added to make searches easier.] --></p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>fib_luc</code>是一个功能。
|
||||
testString: assert(typeof fib_luc === 'function');
|
||||
- text: <code>fib_luc(2,10,"f")</code>应返回<code>[1,1,2,3,5,8,13,21,34,55]</code> 。
|
||||
testString: assert.deepEqual(fib_luc(2,10,"f"),ans[0]);
|
||||
- text: <code>fib_luc(3,15,"f")</code>应返回<code>[1,1,2,4,7,13,24,44,81,149,274,504,927,1705,3136]</code> 。
|
||||
testString: assert.deepEqual(fib_luc(3,15,"f"),ans[1]);
|
||||
- text: <code>fib_luc(4,15,"f")</code>应返回<code>[1,1,2,4,8,15,29,56,108,208,401,773,1490,2872,5536]</code> 。
|
||||
testString: assert.deepEqual(fib_luc(4,15,"f"),ans[2]);
|
||||
- text: <code>fib_luc(2,10,"l")</code>应返回<code>[ 2, 1, 3, 4, 7, 11, 18, 29, 47, 76]</code> <code>fib_luc(2,10,"l")</code> <code>[ 2, 1, 3, 4, 7, 11, 18, 29, 47, 76]</code> 。
|
||||
testString: assert.deepEqual(fib_luc(2,10,"l"),ans[3]);
|
||||
- text: <code>fib_luc(3,15,"l")</code>应返回<code>[ 2, 1, 3, 6, 10, 19, 35, 64, 118, 217, 399, 734, 1350, 2483, 4567 ]</code> <code>fib_luc(3,15,"l")</code> <code>[ 2, 1, 3, 6, 10, 19, 35, 64, 118, 217, 399, 734, 1350, 2483, 4567 ]</code> 。
|
||||
testString: assert.deepEqual(fib_luc(3,15,"l"),ans[4]);
|
||||
- text: <code>fib_luc(4,15,"l")</code>应该返回<code>[ 2, 1, 3, 6, 12, 22, 43, 83, 160, 308, 594, 1145, 2207, 4254, 8200 ]</code> <code>fib_luc(4,15,"l")</code> <code>[ 2, 1, 3, 6, 12, 22, 43, 83, 160, 308, 594, 1145, 2207, 4254, 8200 ]</code> 。
|
||||
testString: assert.deepEqual(fib_luc(4,15,"l"),ans[5]);
|
||||
- text: <code>fib_luc(5,15,"l")</code>应该返回<code>[ 2, 1, 3, 6, 12, 24, 46, 91, 179, 352, 692, 1360, 2674, 5257, 10335 ]</code> 。
|
||||
testString: assert.deepEqual(fib_luc(5,15,"l"),ans[6]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function fib_luc (n, len, w) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,60 @@
|
||||
---
|
||||
title: Fibonacci sequence
|
||||
id: 597f24c1dda4e70f53c79c81
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 斐波那契序列
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>编写一个函数来生成第<big>n <sup>个</sup></big> Fibonacci数。 </p> /// <p>第<big>n <sup>个</sup></big> Fibonacci数由下式给出:/// </p><p> F <sub>n</sub> = F <sub>n-1</sub> + F <sub>n-2</sub> </p> /// <p>该系列的前两个术语是0,1。 </p> /// <p>因此,该系列是:0,1,1,2,3,5,8,13 ...... </p> /// </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>fibonacci</code>是一种功能。
|
||||
testString: assert(typeof fibonacci === 'function');
|
||||
- text: <code>fibonacci(2)</code>应该返回一个数字。
|
||||
testString: assert(typeof fibonacci(2) == 'number');
|
||||
- text: <code>fibonacci(3)</code>应该返回1.“)
|
||||
testString: assert.equal(fibonacci(3),1);
|
||||
- text: <code>fibonacci(5)</code>应该返回3.“)
|
||||
testString: assert.equal(fibonacci(5),3);
|
||||
- text: <code>fibonacci(10)</code>应该返回34.“)
|
||||
testString: assert.equal(fibonacci(10),34);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function fibonacci(n) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,64 @@
|
||||
---
|
||||
title: Fibonacci word
|
||||
id: 5992e222d397f00d21122931
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 斐波那契字
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>编写一个函数将Fibonacci字返回到N.N将作为参数提供给函数。该函数应返回一个对象数组。对象的形式应为:{N:1,长度:1,熵:0,单词:'1'}。更多细节如下: </p><p> Fibonacci Word可以类似于Fibonacci Sequence的方式创建, <a href="http://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf" title="链接:http://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf">如下所述</a> : </p><p>将F_Word <sub>1</sub>定义为1 </p><p>将F_Word <sub>2</sub>定义为0 </p><p>将F_Word <sub>3表示</sub>为F_Word <sub>2</sub>与F_Word <sub>1</sub>连接,即:01 </p><p>将F_Word <sub>n表示</sub>为F_Word <sub>n-1</sub>与F_word <sub>n-2连接</sub> </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>fibWord</code>是一个功能。
|
||||
testString: assert(typeof fibWord === 'function');
|
||||
- text: <code>fibWord(5)</code>应该返回一个数组。
|
||||
testString: assert(Array.isArray(fibWord(5)));
|
||||
- text: '<code>fibWord(5)</code>应该返回<code>'+JSON.stringify(ans)+'</code> 。'
|
||||
testString: assert.deepEqual(fibWord(5),ans);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function fibWord (n) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,72 @@
|
||||
---
|
||||
title: Fractran
|
||||
id: 5a7dad05be01840e1778a0d1
|
||||
challengeType: 3
|
||||
videoUrl: ''
|
||||
localeTitle: Fractran
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><div class="rosetta"><p class="rosetta__paragraph"> <span class="rosetta__text--bold"><a class="rosetta__link--wiki" href="https://en.wikipedia.org/wiki/FRACTRAN" title="wp:FRACTRAN">FRACTRAN</a></span>是由数学家<a class="rosetta__link--wiki" href="https://en.wikipedia.org/wiki/John Horton Conway" title="wp:John Horton Conway">John Horton Conway</a>发明的图灵完备的深奥编程语言。 </p><br><p class="rosetta__paragraph"> FRACTRAN程序是正分数$ P =(f_1,f_2,\ ldots,f_m)$的有序列表,以及初始正整数输入$ n $。 </p><br><p class="rosetta__paragraph">该程序通过更新整数$ n $来运行,如下所示: </p><br><ul class="rosetta__unordered-list"><li class="rosetta__list-item--unordered">对于第一个分数$ f_i $,在$ nf_i $为整数的列表中,用$ nf_i $替换$ n $; </li><li class="rosetta__list-item--unordered">重复此规则,直到列表中没有分数乘以$ n $时产生整数,然后停止。 </li></ul><br><p class="rosetta__paragraph">康威为FRACTRAN提供了素数计划: </p><br><p class="rosetta__paragraph"> <span class="rosetta__text--indented">$ 17/91 $,$ 78/85 $,$ 19/51 $,$ 23/38 $,$ 29/33 $,$ 77/29 $,$ 95/23 $,$ 77/19 $,$ 1/17 $,$ 11/13 $, $ 13/11 $ $,$ 15/14 $,$ 15/2 $,$ 55/1 $</span> </p><br><p class="rosetta__paragraph">从$ n = 2 $开始,此FRACTRAN程序将$ n $更改为$ 15 = 2 \ times(15/2)$,然后$ 825 = 15 \ times(55/1)$,生成以下整数序列: </p><br><p class="rosetta__paragraph"> <span class="rosetta__text--indented">$ 2 $,$ 15 $,$ 825 $,$ 725 $,$ 1925 $,$ 2275 $,$ 425 $,$ 390 $,$ 330 $,$ 290 $,$ 770 $,$ \ ldots $</span> </p><br><p class="rosetta__paragraph"> 2之后,此序列包含以下2的幂: </p><br><p class="rosetta__paragraph"> <span class="rosetta__text--indented">$ 2 ^ 2 = 4 $,$ 2 ^ 3 = 8 $,$ 2 ^ 5 = 32 $,$ 2 ^ 7 = 128 $,$ 2 ^ {11} = 2048 $,$ 2 ^ {13} = 8192 $,$ 2 ^ {17 } = 131072 $,$ 2 ^ {19} = 524288 $,$ \ ldots $</span> </p><br><p class="rosetta__paragraph">这是2的主要权力。 </p><br><dl class="rosetta__description-list"><dt class="rosetta__description-title">任务: </dt></dl><p class="rosetta__paragraph">编写一个函数,将fractran程序作为字符串参数,并将程序的前10个数字作为数组返回。如果结果没有10个数字,则按原样返回数字。 </p></div></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>fractran</code>应该是一个功能。
|
||||
testString: assert(typeof fractran=='function');
|
||||
- text: '<code>fractran(""+tests[0]+"")</code>应该返回一个数组。'
|
||||
testString: assert(Array.isArray(fractran('3/2, 1/3')));
|
||||
- text: '<code>fractran(""+tests[0]+"")</code>应返回<code>"+JSON.stringify(results[0])+"</code> 。'
|
||||
testString: assert.deepEqual(fractran('3/2, 1/3'), [ 2, 3, 1 ]);
|
||||
- text: '<code>fractran(""+tests[1]+"")</code>应返回<code>"+JSON.stringify(results[1])+"</code> 。'
|
||||
testString: assert.deepEqual(fractran('3/2, 5/3, 1/5'), [ 2, 3, 5, 1 ]);
|
||||
- text: '<code>fractran(""+tests[2]+"")</code>应返回<code>"+JSON.stringify(results[2])+"</code> 。'
|
||||
testString: assert.deepEqual(fractran('3/2, 6/3'), [ 2, 3, 6, 9, 18, 27, 54, 81, 162, 243 ]);
|
||||
- text: '<code>fractran(""+tests[3]+"")</code>应返回<code>"+JSON.stringify(results[3])+"</code> 。'
|
||||
testString: assert.deepEqual(fractran('2/7, 7/2'), [ 2, 7, 2, 7, 2, 7, 2, 7, 2, 7 ]);
|
||||
- text: '<code>fractran(""+tests[4]+"")</code>应返回<code>"+JSON.stringify(results[4])+"</code> 。'
|
||||
testString: assert.deepEqual(fractran('17/91, 78/85, 19/51, 23/38, 29/33, 77/29, 95/23, 77/19, 1/17, 11/13, 13/11, 15/14, 15/2, 55/1'), [ 2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290 ]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function fractran (progStr) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,72 @@
|
||||
---
|
||||
title: Gamma function
|
||||
id: 5a23c84252665b21eecc7e76
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 伽玛功能
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">实现一个算法(或更多)来计算<a href="https://en.wikipedia.org/wiki/Gamma function">Gamma</a> ($ \ Gamma $)函数(仅在实际字段中)。 Gamma功能可以定义为: <div style="padding-left: 4em;"> <big><big>$ \ Gamma(x)= \ displaystyle \ int_0 ^ \ infty t ^ {x-1} e ^ { - t} dt $</big></big> </div></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>gamma</code>应该是一个功能。
|
||||
testString: assert(typeof gamma=='function')
|
||||
- text: '<code>gamma("+tests[0]+")</code>应该返回一个数字。'
|
||||
testString: assert(typeof gamma(.1)=='number')
|
||||
- text: '<code>gamma("+tests[0]+")</code>应该返回<code>"+results[0]+"</code> 。'
|
||||
testString: assert.equal(round(gamma(.1)), round(9.513507698668736))
|
||||
- text: '<code>gamma("+tests[1]+")</code>应该返回<code>"+results[1]+"</code> 。'
|
||||
testString: assert.equal(round(gamma(.2)), round(4.590843711998803))
|
||||
- text: '<code>gamma("+tests[2]+")</code>应该返回<code>"+results[2]+"</code> 。'
|
||||
testString: assert.equal(round(gamma(.3)), round(2.9915689876875904))
|
||||
- text: '<code>gamma("+tests[3]+")</code>应该返回<code>"+results[3]+"</code> 。'
|
||||
testString: assert.equal(round(gamma(.4)), round(2.218159543757687))
|
||||
- text: '<code>gamma("+tests[4]+")</code>应返回<code>"+results[4]+"</code> 。'
|
||||
testString: assert.equal(round(gamma(.5)), round(1.7724538509055159))
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function gamma (x) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,72 @@
|
||||
---
|
||||
title: Gaussian elimination
|
||||
id: 5a23c84252665b21eecc7e77
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 高斯消除
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">编写一个函数来解决\(Ax = b \)使用高斯消除然后向后替换。 \(A \)是\(n \次n \)矩阵。此外,\(x \)和\(b \)是\(n \)乘以1个向量。要提高准确性,请使用部分旋转和缩放。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>gaussianElimination</code>应该是一个函数。
|
||||
testString: assert(typeof gaussianElimination=='function');
|
||||
- text: '<code>gaussianElimination("+JSON.stringify(tests[0][0])+","+JSON.stringify(tests[0][1])+")</code>应该返回一个数组。'
|
||||
testString: assert(Array.isArray(gaussianElimination([[1,1],[1,-1]], [5,1])));
|
||||
- text: '<code>gaussianElimination("+JSON.stringify(tests[0][0])+","+JSON.stringify(tests[0][1])+")</code>应返回<code>"+JSON.stringify(results[0])+"</code> 。'
|
||||
testString: assert.deepEqual(gaussianElimination([[1,1],[1,-1]], [5,1]), [ 3, 2 ]);
|
||||
- text: '<code>gaussianElimination("+JSON.stringify(tests[1][0])+","+JSON.stringify(tests[1][1])+")</code>应返回<code>"+JSON.stringify(results[1])+"</code> 。'
|
||||
testString: assert.deepEqual(gaussianElimination([[2,3],[2,1]] , [8,4]), [ 1, 2 ]);
|
||||
- text: '<code>gaussianElimination("+JSON.stringify(tests[2][0])+","+JSON.stringify(tests[2][1])+")</code>应返回<code>"+JSON.stringify(results[2])+"</code> 。'
|
||||
testString: assert.deepEqual(gaussianElimination([[1,3],[5,-2]], [14,19]), [ 5, 3 ]);
|
||||
- text: '<code>gaussianElimination("+JSON.stringify(tests[3][0])+","+JSON.stringify(tests[3][1])+")</code>应返回<code>"+JSON.stringify(results[3])+"</code> 。'
|
||||
testString: assert.deepEqual(gaussianElimination([[1,1],[5,-1]] , [10,14]), [ 4, 6 ]);
|
||||
- text: '<code>gaussianElimination("+JSON.stringify(tests[4][0])+","+JSON.stringify(tests[4][1])+")</code>应返回<code>"+JSON.stringify(results[4])+"</code> 。'
|
||||
testString: assert.deepEqual(gaussianElimination([[1,2,3],[4,5,6],[7,8,8]] , [6,15,23]), [ 1, 1, 1 ]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function gaussianElimination (A,b) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,76 @@
|
||||
---
|
||||
title: General FizzBuzz
|
||||
id: 5a23c84252665b21eecc7e78
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 一般的FizzBuzz
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">编写<a href="http://rosettacode.org/wiki/FizzBuzz">FizzBuzz</a>的通用版本,适用于任何因子列表及其单词。这基本上是一种“fizzbuzz”实现,其中游戏规则被提供给用户。创建一个实现此功能的函数。该函数应该有两个参数。第一个是带有FizzBuzz规则的数组。例如: <code>[ [3,"Fizz"] , [5,"Buzz"] ]</code> 。此indcates该<code>Fizz</code> ,如果数量是3的倍数,并应被打印<code>Buzz</code>如果是5的倍数。如果它是两则字符串应该在阵列中指定的顺序被连结的倍数。在这种情况下,如果数字是3和5的倍数,则为<code>FizzBuzz</code> 。第二个参数是函数应返回如上所述的字符串的数字。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>genFizzBuzz</code>应该是一个功能。
|
||||
testString: assert(typeof genFizzBuzz=='function');
|
||||
- text: <code>genFizzBuzz("+JSON.stringify(tests[0][0])+","+tests[0][1]+")</code>应该返回一个类型。
|
||||
testString: assert(typeof genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 6)=='string');
|
||||
- text: <code>genFizzBuzz("+JSON.stringify(tests[0][0])+","+tests[0][1]+")</code>应返回<code>""+results[0]+""</code> 。
|
||||
testString: assert.equal(genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 6), "Fizz");
|
||||
- text: <code>genFizzBuzz("+JSON.stringify(tests[1][0])+","+tests[1][1]+")</code>应返回<code>""+results[1]+""</code> 。
|
||||
testString: assert.equal(genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 10), "Buzz");
|
||||
- text: <code>genFizzBuzz("+JSON.stringify(tests[2][0])+","+tests[2][1]+")</code>应返回<code>""+results[2]+""</code> 。
|
||||
testString: assert.equal(genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 12), "Buzz");
|
||||
- text: <code>genFizzBuzz("+JSON.stringify(tests[3][0])+","+tests[3][1]+")</code>应返回<code>""+results[3]+""</code> 。
|
||||
testString: assert.equal(genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 13), '13');
|
||||
- text: <code>genFizzBuzz("+JSON.stringify(tests[4][0])+","+tests[4][1]+")</code>应该返回<code>""+results[4]+""</code> 。
|
||||
testString: assert.equal(genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 15), "BuzzFizz");
|
||||
- text: <code>genFizzBuzz("+JSON.stringify(tests[5][0])+","+tests[5][1]+")</code>应返回<code>""+results[5]+""</code> 。
|
||||
testString: assert.equal(genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 15), "FizzBuzz");
|
||||
- text: <code>genFizzBuzz("+JSON.stringify(tests[6][0])+","+tests[6][1]+")</code>应该返回<code>""+results[6]+""</code> 。
|
||||
testString: assert.equal(genFizzBuzz([[3, "Fizz"],[5, "Buzz"],[7, "Baxx"]], 105), "FizzBuzzBaxx");
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function genFizzBuzz (rules, num) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,72 @@
|
||||
---
|
||||
title: Generate lower case ASCII alphabet
|
||||
id: 5a23c84252665b21eecc7e7a
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 生成小写ASCII字母表
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">编写一个函数以生成给定范围的小写ASCII字符数组。例如:对于范围1到4,函数应返回<code>['a','b','c','d']</code> 。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>lascii</code>应该是一个功能。
|
||||
testString: assert(typeof lascii=='function');
|
||||
- text: <code>lascii("a","d")</code>应该返回一个数组。
|
||||
testString: assert(Array.isArray(lascii('a','d')));
|
||||
- text: <code>lascii("a","d")</code>应该返回<code>[ "a", "b", "c", "d" ]</code> 。
|
||||
testString: assert.deepEqual(lascii("a","d"),results[0]);
|
||||
- text: <code>lascii("c","i")</code>应该返回<code>[ "c", "d", "e", "f", "g", "h", "i" ]</code> 。
|
||||
testString: assert.deepEqual(lascii("c","i"),results[1]);
|
||||
- text: <code>lascii("m","q")</code>应该返回<code>[ "m", "n", "o", "p", "q" ]</code> 。
|
||||
testString: assert.deepEqual(lascii("m","q"),results[2]);
|
||||
- text: <code>lascii("k","n")</code>应返回<code>[ "k", "l", "m", "n" ]</code> 。
|
||||
testString: assert.deepEqual(lascii("k","n"),results[3]);
|
||||
- text: <code>lascii("t","z")</code>应该返回<code>[ "t", "u", "v", "w", "x", "y", "z" ]</code> 。
|
||||
testString: assert.deepEqual(lascii("t","z"),results[4]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function lascii (cFrom, cTo) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,66 @@
|
||||
---
|
||||
title: Gray code
|
||||
id: 5a23c84252665b21eecc7e80
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 格雷码
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <a href="https://en.wikipedia.org/wiki/Gray code">格雷码</a>是二进制编码的一种形式,其中连续数字之间的转换仅相差一位。这是一种有用的编码,用于减少硬件数据危险,其值快速变化和/或连接到较慢的硬件作为输入。从左到右或从上到下依次为<a href="https://en.wikipedia.org/wiki/Karnaugh map">卡诺图</a>生成输入也很有用。创建一个函数来编码数字并解码格雷码中的数字。该函数应该有2个参数。第一个是布尔值。该函数应编码为true,解码为false。第二个参数是要编码/解码的数字。显示所有5位二进制数的正常二进制表示,格雷码表示和解码格雷码值(0-31包括0,不需要前导0)。有许多可能的格雷码。以下编码所谓的“二进制反射格雷码”。 <br>编码(MSB为0位,b为二进制,g为格雷码): <code><br> if b[i-1] = 1 <br> <span style="padding-left:1em">g[i] = not b[i]</span> <br> else <br> <span style="padding-left:1em">g[i] = b[i]</span> <br></code>要么: <br> <code>g = b xor (b logically right shifted 1 time)</code> <br>解码(MSB为0位,b为二进制,g为格雷码): <br> <code>b[0] = g[0] <br> for other bits: <br> b[i] = g[i] xor b[i-1] <br></code> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>gray</code>应该是一个功能。
|
||||
testString: assert(typeof gray=='function');
|
||||
- text: '<code>gray(true,177)</code>应该返回一个数字。'
|
||||
testString: assert(typeof gray(true,177)=='number');
|
||||
- text: '<code>gray(true,177)</code>应该返回<code>233</code> 。'
|
||||
testString: assert.equal(gray(true,177),233);
|
||||
- text: '<code>gray(true,425)</code>应该返回<code>381</code> 。'
|
||||
testString: assert.equal(gray(true,425),381);
|
||||
- text: '<code>gray(true,870)</code>应该返回<code>725</code> 。'
|
||||
testString: assert.equal(gray(true,870),725);
|
||||
- text: '<code>gray(false,233)</code>应该返回<code>177</code> 。'
|
||||
testString: assert.equal(gray(false,233),177);
|
||||
- text: '<code>gray(false,381)</code>应该返回<code>425</code> 。'
|
||||
testString: assert.equal(gray(false,381),425);
|
||||
- text: '<code>gray(false,725)</code>应该返回<code>870</code> 。'
|
||||
testString: assert.equal(gray(false,725),870);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function gray(enc, number) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,66 @@
|
||||
---
|
||||
title: Greatest common divisor
|
||||
id: 5a23c84252665b21eecc7e82
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 最大公约数
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">编写一个函数,返回两个整数的最大公约数。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>gcd</code>应该是一个功能。
|
||||
testString: assert(typeof gcd=='function');
|
||||
- text: '<code>gcd(24,36)</code>应该返回一个数字。'
|
||||
testString: assert(typeof gcd(24,36)=='number');
|
||||
- text: '<code>gcd(24,36)</code>应该返回<code>12</code> 。'
|
||||
testString: assert.equal(gcd(24,36),12);
|
||||
- text: '<code>gcd(30,48)</code>应该返回<code>6</code> 。'
|
||||
testString: assert.equal(gcd(30,48),6);
|
||||
- text: '<code>gcd(10,15)</code>应该返回<code>5</code> 。'
|
||||
testString: assert.equal(gcd(10,15),5);
|
||||
- text: '<code>gcd(100,25)</code>应该返回<code>25</code> 。'
|
||||
testString: assert.equal(gcd(100,25),25);
|
||||
- text: '<code>gcd(13,250)</code>应该返回<code>1</code> 。'
|
||||
testString: assert.equal(gcd(13,250),1);
|
||||
- text: '<code>gcd(1300,250)</code>应该返回<code>50</code> 。'
|
||||
testString: assert.equal(gcd(1300,250),50);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function gcd(a, b) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,74 @@
|
||||
---
|
||||
title: Greatest subsequential sum
|
||||
id: 5a23c84252665b21eecc7e84
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 最重要的后续总和
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">给定一个整数序列,找到一个连续的子序列,它最大化其元素的总和,也就是说,没有其他单个子序列的元素加起来大于这一个的值。空子序列被认为具有\(0 \)的总和;因此,如果所有元素都是负数,则结果必须是空序列。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>maximumSubsequence</code>应该是一个函数。
|
||||
testString: assert(typeof maximumSubsequence=='function');
|
||||
- text: '<code>maximumSubsequence("+JSON.stringify(tests[0])+")</code>应该返回一个数组。'
|
||||
testString: assert(Array.isArray(maximumSubsequence([ 1, 2,-1, 3, 10, -10 ])));
|
||||
- text: '<code>maximumSubsequence("+JSON.stringify(tests[0])+")</code>应返回<code>"+JSON.stringify(results[0])+"</code> 。'
|
||||
testString: assert.deepEqual(maximumSubsequence([1,2,-1,3,10,-10]), [ 1, 2, -1, 3, 10 ]);
|
||||
- text: '<code>maximumSubsequence("+JSON.stringify(tests[1])+")</code>应返回<code>"+JSON.stringify(results[1])+"</code> 。'
|
||||
testString: assert.deepEqual(maximumSubsequence([0, 8, 10, -2, -4, -1, -5, -3]), [ 0, 8, 10 ]);
|
||||
- text: '<code>maximumSubsequence("+JSON.stringify(tests[2])+")</code>应返回<code>"+JSON.stringify(results[2])+"</code> 。'
|
||||
testString: assert.deepEqual(maximumSubsequence([ 9, 9, -10, 1 ]), [ 9, 9 ]);
|
||||
- text: '<code>maximumSubsequence("+JSON.stringify(tests[3])+")</code>应返回<code>"+JSON.stringify(results[3])+"</code> 。'
|
||||
testString: assert.deepEqual(maximumSubsequence([ 7, 1, -5, -3, -8, 1 ]), [ 7, 1 ]);
|
||||
- text: '<code>maximumSubsequence("+JSON.stringify(tests[4])+")</code>应返回<code>"+JSON.stringify(results[4])+"</code> 。'
|
||||
testString: assert.deepEqual(maximumSubsequence([ -3, 6, -1, 4, -4, -6 ]), [ 6, -1, 4 ]);
|
||||
- text: '<code>maximumSubsequence("+JSON.stringify(tests[5])+")</code>应返回<code>"+JSON.stringify(results[5])+"</code> 。'
|
||||
testString: assert.deepEqual(maximumSubsequence([ -1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1 ]), [ 3, 5, 6, -2, -1, 4 ]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function maximumSubsequence (population) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,66 @@
|
||||
---
|
||||
title: Hailstone sequence
|
||||
id: 595608ff8bcd7a50bd490181
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 冰雹序列
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p> Hailstone数字序列可以从起始正整数n生成: </p>如果n为1,则序列结束。如果n是偶数,那么序列的下一个n <code>= n/2</code>如果n是奇数,那么序列的下一个n <code>= (3 * n) + 1</code> <p> (未经证实的) <a href="https://en.wikipedia.org/wiki/Collatz conjecture" title="wp:Collatz猜想">Collatz猜想</a>是任何起始编号的冰雹序列总是终止。 </p><p>冰雹序列也称为冰雹数(因为这些值通常受到多个下降和上升,如云中的冰雹),或者作为Collatz序列。 </p>任务:创建例程以生成数字的hailstone序列。使用例程表明,对于27号的冰雹序列具有开始与112个元件<code>27, 82, 41, 124</code> ,结束时用<code>8, 4, 2, 1</code>与显示具有最长冰雹序列的数目少于100,000一起序列的长度。 (但不要显示实际的序列!)参见: <a href="http://xkcd.com/710" title="链接:http://xkcd.com/710">xkcd</a> (幽默)。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>hailstoneSequence</code>是一个函数。
|
||||
testString: assert(typeof hailstoneSequence === '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);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// noprotect
|
||||
function hailstoneSequence () {
|
||||
const res = [];
|
||||
// Good luck!
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,76 @@
|
||||
---
|
||||
title: Happy numbers
|
||||
id: 594810f028c0303b75339ad1
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 快乐的数字
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>幸福的数字由以下过程定义: </p><p>从任何正整数开始,将数字替换为其数字的平方和,并重复该过程直到数字等于1(它将保持不变),或者它在一个不包括1的循环中无休止地循环。这些数字这个过程在1结束的是幸福的数字,而那些不以1结尾的数字是不愉快的数字。 </p><p>实现一个函数,如果数字是满意的,则返回true,否则返回false。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>happy</code>是一种功能。
|
||||
testString: assert(typeof happy === 'function');
|
||||
- text: <code>happy(1)</code>应该返回一个布尔值。
|
||||
testString: assert(typeof happy(1) === 'boolean');
|
||||
- text: <code>happy(1)</code>应该回归真实。
|
||||
testString: assert(happy(1));
|
||||
- text: <code>happy(2)</code>应该返回虚假。
|
||||
testString: assert(!happy(2));
|
||||
- text: <code>happy(7)</code>应该回归真实。
|
||||
testString: assert(happy(7));
|
||||
- text: <code>happy(10)</code>应该回归真实。
|
||||
testString: assert(happy(10));
|
||||
- text: <code>happy(13)</code>应该回归真实。
|
||||
testString: assert(happy(13));
|
||||
- text: <code>happy(19)</code>应该回归真实。
|
||||
testString: assert(happy(19));
|
||||
- text: <code>happy(23)</code>应该回归真实。
|
||||
testString: assert(happy(23));
|
||||
- text: <code>happy(28)</code>应该回归真实。
|
||||
testString: assert(happy(28));
|
||||
- text: <code>happy(31)</code>应该回归真实。
|
||||
testString: assert(happy(31));
|
||||
- text: <code>happy(32)</code>应该回归真实:
|
||||
testString: assert(happy(32));
|
||||
- text: <code>happy(33)</code>应该返回虚假。
|
||||
testString: assert(!happy(33));
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function happy (number) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,68 @@
|
||||
---
|
||||
title: Harshad or Niven series
|
||||
id: 595668ca4cfe1af2fb9818d4
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: Harshad或Niven系列
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p> <a href="http://mathworld.wolfram.com/HarshadNumber.html" title="链接:http://mathworld.wolfram.com/HarshadNumber.html">Harshad</a>或Niven数是正整数≥1,可以被它们的数字之和整除。 </p><p>例如,42是<a href="http://rosettacode.org/wiki/oeis:A005349" title="OEIS:A005349">Harshad数,</a>因为42可以被(4 + 2)整除而没有余数。 </p>假设系列被定义为按递增顺序排列的数字。任务: <p>实现一个函数来生成Harshad序列的连续成员。 </p><p>使用它列出序列的前20个成员并列出第一个大于1000的Harshad数。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>isHarshadOrNiven</code>是一个函数。
|
||||
testString: assert(typeof isHarshadOrNiven === 'function');
|
||||
- text: '<code>isHarshadOrNiven()</code>应该返回<code>{"firstTwenty": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42],"firstOver1000": 1002}</code>'
|
||||
testString: assert.deepEqual(isHarshadOrNiven(), res);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function isHarshadOrNiven () {
|
||||
const res = {
|
||||
firstTwenty: [],
|
||||
firstOver1000: undefined
|
||||
};
|
||||
// Change after this line
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,73 @@
|
||||
---
|
||||
title: Hash from two arrays
|
||||
id: 595671d4d2cdc305f0d5b36f
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 来自两个数组的哈希
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>使用两个相等长度的数组,创建一个Hash对象,其中一个数组中的元素(键)链接到另一个数组(值) </p>相关任务: <a href="http://rosettacode.org/wiki/Associative arrays/Creation" title="关联数组/创建">关联数组/创建</a> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>arrToObj</code>是一个功能。
|
||||
testString: assert(typeof arrToObj === 'function');
|
||||
- text: '<code>arrToObj([1, 2, 3, 4, 5], ["a", "b", "c", "d", "e"])</code>应返回<code>{ 1: "a", 2: "b", 3: "c", 4: "d", 5: "e" }</code>'
|
||||
testString: assert.deepEqual(arrToObj(...testCases[0]), res[0]);
|
||||
- text: '<code>arrToObj([1, 2, 3, 4, 5], ["a", "b", "c", "d"])</code>应返回<code>{ 1: "a", 2: "b", 3: "c", 4: "d", 5: undefined }</code>'
|
||||
testString: assert.deepEqual(arrToObj(...testCases[1]), res[1]);
|
||||
- text: '<code>arrToObj([1, 2, 3], ["a", "b", "c", "d", "e"])</code>应返回<code>{ 1: "a", 2: "b", 3: "c" }</code>'
|
||||
testString: assert.deepEqual(arrToObj(...testCases[2]), res[2]);
|
||||
- text: '<code>arrToObj(["a", "b", "c", "d", "e"], [1, 2, 3, 4, 5])</code>应返回<code>{ "a": 1, "b": 2, "c": 3 , "d": 4, "e": 5 }</code>'
|
||||
testString: assert.deepEqual(arrToObj(...testCases[3]), res[3]);
|
||||
- text: '<code>arrToObj(["a", "b", "c", "d", "e"], [1, 2, 3, 4])</code>应返回<code>{ "a": 1, "b": 2, "c": 3 , "d": 4, "e": undefined }</code>'
|
||||
testString: assert.deepEqual(arrToObj(...testCases[4]), res[4]);
|
||||
- text: '<code>arrToObj(["a", "b", "c"], [1, 2, 3, 4, 5])</code>应返回<code>{ "a": 1, "b": 2, "c": 3 }</code>'
|
||||
testString: assert.deepEqual(arrToObj(...testCases[5]), res[5]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function arrToObj (keys, vals) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,75 @@
|
||||
---
|
||||
title: Hash join
|
||||
id: 5956795bc9e2c415eb244de1
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 哈希加入
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p> <a href="https://en.wikipedia.org/wiki/Join_(SQL)#Inner_join" title="wp:Join_(SQL)#Inner_join">内连接</a>是一种操作,它根据匹配的列值将两个数据表组合到一个表中。实现此操作的最简单方法是<a href="https://en.wikipedia.org/wiki/Nested loop join" title="wp:嵌套循环连接">嵌套循环连接</a>算法,但更可扩展的替代方法是<a href="https://en.wikipedia.org/wiki/hash join" title="wp:哈希联接">散列连接</a>算法。 </p><p>实现“散列连接”算法,并演示它通过下面列出的测试用例。 </p><p>您应该将表表示为在编程语言中感觉自然的数据结构。 </p><p> “散列连接”算法包含两个步骤: </p>哈希阶段:从两个表中的一个表创建一个<a href="https://en.wikipedia.org/wiki/Multimap" title="wp:Multimap">多</a>图,从每个连接列值映射到包含它的所有行。多图必须支持基于散列的查找,它比简单的线性搜索更好地扩展,因为这是该算法的重点。理想情况下,我们应该为较小的表创建多图,从而最小化其创建时间和内存大小。加入阶段:扫描另一个表,通过查看之前创建的多图来查找匹配的行。 <p>在伪代码中,算法可以表示如下: </p><pre>让A =第一个输入表(或理想情况下,更大的输入表)
|
||||
设B =第二个输入表(或理想情况下,较小的输入表)
|
||||
令j <sub>A</sub> =表A的连接列ID
|
||||
令j <sub>B</sub> =表B的连接列ID
|
||||
让M <sub>B</sub> =一个多图,用于从单个值映射到表B的多行(从空白开始)
|
||||
让C =输出表(从空开始)
|
||||
对于表B中的每一行b:
|
||||
将b放在密钥b(j <sub>B</sub> )下的多映射M <sub>B中</sub>
|
||||
对于表A中的每一行a:
|
||||
对于a(j <sub>A</sub> )项下多图M <sub>B中的</sub>每一行b:
|
||||
设c =第a行和第b行的串联
|
||||
将行c放在表C中<p></p>
|
||||
</pre>测试用例<p>输入</p><table><tbody><tr><td style="padding: 4px; margin: 5px;"><table style="border:none; border-collapse:collapse;"><tbody><tr><td style="border:none"> <i>A =</i> </td><td style="border:none"><table><tbody><tr><th style="padding: 4px; margin: 5px;">年龄</th><th style="padding: 4px; margin: 5px;">名称</th></tr><tr><td style="padding: 4px; margin: 5px;"> 27 </td><td style="padding: 4px; margin: 5px;">约拿</td></tr><tr><td style="padding: 4px; margin: 5px;"> 18 </td><td style="padding: 4px; margin: 5px;">艾伦</td></tr><tr><td style="padding: 4px; margin: 5px;"> 28 </td><td style="padding: 4px; margin: 5px;">荣耀</td></tr><tr><td style="padding: 4px; margin: 5px;"> 18 </td><td style="padding: 4px; margin: 5px;">大力水手</td></tr><tr><td style="padding: 4px; margin: 5px;"> 28 </td><td style="padding: 4px; margin: 5px;">艾伦</td></tr></tbody></table></td><td style="border:none; padding-left:1.5em;" rowspan="2"></td><td style="border:none"> <i>B =</i> </td><td style="border:none"><table><tbody><tr><th style="padding: 4px; margin: 5px;">字符</th><th style="padding: 4px; margin: 5px;">复仇者</th></tr><tr><td style="padding: 4px; margin: 5px;">约拿</td><td style="padding: 4px; margin: 5px;">鲸鱼</td></tr><tr><td style="padding: 4px; margin: 5px;">约拿</td><td style="padding: 4px; margin: 5px;">蜘蛛</td></tr><tr><td style="padding: 4px; margin: 5px;">艾伦</td><td style="padding: 4px; margin: 5px;">鬼</td></tr><tr><td style="padding: 4px; margin: 5px;">艾伦</td><td style="padding: 4px; margin: 5px;">植物大战僵尸</td></tr><tr><td style="padding: 4px; margin: 5px;">荣耀</td><td style="padding: 4px; margin: 5px;">巴菲</td></tr></tbody></table></td></tr><tr><td style="border:none"> <i>j <sub>A</sub> =</i> </td><td style="border:none"> <i><code>Name</code> (即第1栏)</i> </td><td style="border:none"> <i>j <sub>B</sub> =</i> </td><td style="border:none"> <i><code>Character</code> (即第0列)</i> </td></tr></tbody></table></td><td style="padding: 4px; margin: 5px;"></td></tr></tbody></table><p>产量</p><table><tbody><tr><th style="padding: 4px; margin: 5px;"> A.Age </th><th style="padding: 4px; margin: 5px;">一个名字</th><th style="padding: 4px; margin: 5px;"> B.Character </th><th style="padding: 4px; margin: 5px;"> B.Nemesis </th></tr><tr><td style="padding: 4px; margin: 5px;"> 27 </td><td style="padding: 4px; margin: 5px;">约拿</td><td style="padding: 4px; margin: 5px;">约拿</td><td style="padding: 4px; margin: 5px;">鲸鱼</td></tr><tr><td style="padding: 4px; margin: 5px;"> 27 </td><td style="padding: 4px; margin: 5px;">约拿</td><td style="padding: 4px; margin: 5px;">约拿</td><td style="padding: 4px; margin: 5px;">蜘蛛</td></tr><tr><td style="padding: 4px; margin: 5px;"> 18 </td><td style="padding: 4px; margin: 5px;">艾伦</td><td style="padding: 4px; margin: 5px;">艾伦</td><td style="padding: 4px; margin: 5px;">鬼</td></tr><tr><td style="padding: 4px; margin: 5px;"> 18 </td><td style="padding: 4px; margin: 5px;">艾伦</td><td style="padding: 4px; margin: 5px;">艾伦</td><td style="padding: 4px; margin: 5px;">植物大战僵尸</td></tr><tr><td style="padding: 4px; margin: 5px;"> 28 </td><td style="padding: 4px; margin: 5px;">荣耀</td><td style="padding: 4px; margin: 5px;">荣耀</td><td style="padding: 4px; margin: 5px;">巴菲</td></tr><tr><td style="padding: 4px; margin: 5px;"> 28 </td><td style="padding: 4px; margin: 5px;">艾伦</td><td style="padding: 4px; margin: 5px;">艾伦</td><td style="padding: 4px; margin: 5px;">鬼</td></tr><tr><td style="padding: 4px; margin: 5px;"> 28 </td><td style="padding: 4px; margin: 5px;">艾伦</td><td style="padding: 4px; margin: 5px;">艾伦</td><td style="padding: 4px; margin: 5px;">植物大战僵尸</td></tr></tbody></table><p></p><p></p><p>输出表中行的顺序并不重要。 </p><p>如果你使用数字索引数组来表示表行(而不是按名称引用列),你可以用<code style="white-space:nowrap">[[27, "Jonah"], ["Jonah", "Whales"]]</code>的形式表示输出行。 。 </p><hr></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>hashJoin</code>是一个函数。
|
||||
testString: assert(typeof hashJoin === 'function');
|
||||
- text: '<code>hashJoin([{ age: 27, name: "Jonah" }, { age: 18, name: "Alan" }, { age: 28, name: "Glory" }, { age: 18, name: "Popeye" }, { age: 28, name: "Alan" }], [{ character: "Jonah", nemesis: "Whales" }, { character: "Jonah", nemesis: "Spiders" }, { character: "Alan", nemesis: "Ghosts" }, { character:"Alan", nemesis: "Zombies" }, { character: "Glory", nemesis: "Buffy" }, { character: "Bob", nemesis: "foo" }])</code>应该返回<code>[{"A_age": 27,"A_name": "Jonah", "B_character": "Jonah", "B_nemesis": "Whales"}, {"A_age": 27,"A_name": "Jonah", "B_character": "Jonah", "B_nemesis": "Spiders"}, {"A_age": 18,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Ghosts"}, {"A_age": 18,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Zombies"}, {"A_age": 28,"A_name": "Glory", "B_character": "Glory", "B_nemesis": "Buffy"}, {"A_age": 28,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Ghosts"}, {"A_age": 28,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Zombies"}]</code>'
|
||||
testString: assert.deepEqual(hashJoin(hash1, hash2), res);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function hashJoin (hash1, hash2) {
|
||||
// Good luck!
|
||||
return [];
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,71 @@
|
||||
---
|
||||
title: Heronian triangles
|
||||
id: 595b98f8b5a2245e243aa831
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 苍鹭三角形
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>给出三边<big>a,</big> <big>b</big>和<big>c</big>长度的三角形区域的<a href="https://en.wikipedia.org/wiki/Heron's formula" title="wp:苍鹭的配方">英雄公式</a>由下<a href="https://en.wikipedia.org/wiki/Heron's formula" title="wp:苍鹭的配方">式</a>给出: </p><p> <big>$$ A = \ sqrt {s(sa)(sb)(sc)},$$</big> </p><p>其中<big>s</big>是三角形的一半周长;那是, </p><p> <big>$$ S = \压裂{A + B + C} {2} $$。</big> </p><p> <a href="http://www.had2know.com/academics/heronian-triangles-generator-calculator.html" title="链接:http://www.had2know.com/academics/heronian-triangles-generator-calculator.html">Heronian三角形</a>是三角形,其边和面都是整数。 </p><p>一个例子是边长为3,4,5的三角形,其面积为6(其周长为12)。 </p><p>注意任何三角形的边都是3,4,5的整数倍;如6,8,10,也将是一个苍鹭三角形。 </p><p>将原始的Heronian三角形定义为最大公约数的Heronian三角形</p><p>三方都是1(统一)。 </p><p>这将排除例如三角形6,8,10。 </p>任务: <p>实现一个基于Hero公式的函数,该函数返回数组数组中的前<code>n <sub>th</sub></code>有序三角形。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>heronianTriangle</code>是一个函数。
|
||||
testString: assert(typeof heronianTriangle === 'function');
|
||||
- text: '<code>heronianTriangle()</code>应返回<code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17]]</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17]]</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17]]</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17]]</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17]]</code>'
|
||||
testString: assert.deepEqual(heronianTriangle(testCases[0]), res[0]);
|
||||
- text: '<code>heronianTriangle()</code>应返回<code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15]],</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15]],</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15]],</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15]],</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15]],</code>'
|
||||
testString: assert.deepEqual(heronianTriangle(testCases[1]), res[1]);
|
||||
- text: '<code>heronianTriangle()</code>应返回<code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53]],</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53]],</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53]],</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53]],</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53]],</code>'
|
||||
testString: assert.deepEqual(heronianTriangle(testCases[2]), res[2]);
|
||||
- text: '<code>heronianTriangle()</code>应返回<code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53], [19, 20, 37],[16, 17, 17], [17, 17, 30], [16, 25, 39], [13, 20, 21]]</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53], [19, 20, 37],[16, 17, 17], [17, 17, 30], [16, 25, 39], [13, 20, 21]]</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53], [19, 20, 37],[16, 17, 17], [17, 17, 30], [16, 25, 39], [13, 20, 21]]</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53], [19, 20, 37],[16, 17, 17], [17, 17, 30], [16, 25, 39], [13, 20, 21]]</code> <code>heronianTriangle()</code> <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53], [19, 20, 37],[16, 17, 17], [17, 17, 30], [16, 25, 39], [13, 20, 21]]</code>'
|
||||
testString: assert.deepEqual(heronianTriangle(testCases[3]), res[3]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// noprotect
|
||||
function heronianTriangle (n) {
|
||||
// Good luck!
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,87 @@
|
||||
---
|
||||
title: Hofstadter Figure-Figure sequences
|
||||
id: 59622f89e4e137560018a40e
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: Hofstadter图 - 图序列
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>这两个正整数序列定义为: </p><p> <big>$$ R(1)= 1 \; \ S(1)= 2 \\ R(n)= R(n-1)+ S(n-1),\ quad n> 1. $$</big> </p><p>序列<big>$ S(n)$</big>进一步定义为<big>$ R(n)$中</big>不存在的正整数序列。 </p><p>序列<big>$ R $</big>开始: </p><p> 1,3,7,12,18 ...... </p><p>序列<big>$ S $</big>开始: </p><p> 2,4,5,6,8 ...... </p>任务:创建两个名为ffr和ffs的函数,当给定n分别返回R(n)或S(n)时(注意R(1)= 1且S(1)= 2以避免逐个错误) 。不应假设n的最大值。 Sloane的<a href="http://oeis.org/A005228" title="链接:http://oeis.org/A005228">A005228</a>和<a href="http://oeis.org/A030124" title="链接:http://oeis.org/A030124">A030124</a> 。 <a href="http://mathworld.wolfram.com/HofstadterFigure-FigureSequence.html" title="链接:http://mathworld.wolfram.com/HofstadterFigure-FigureSequence.html">Wolfram MathWorld</a>维基百科: <a href="https://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Figure-Figure_sequences" title="wp:Hofstadter_sequence#Hofstadter_Figure-Figure_sequences">Hofstadter图 - 图序列</a> 。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>ffr</code>是一个功能。
|
||||
testString: assert(typeof ffr === 'function');
|
||||
- text: <code>ffs</code>是一个函数。
|
||||
testString: assert(typeof ffs === 'function');
|
||||
- text: <code>ffr</code>应该返回整数。
|
||||
testString: assert(Number.isInteger(ffr(1)));
|
||||
- text: <code>ffs</code>应该返回整数。
|
||||
testString: assert(Number.isInteger(ffs(1)));
|
||||
- text: <code>ffr()</code>应该返回<code>69</code>
|
||||
testString: assert.equal(ffr(ffrParamRes[0][0]), ffrParamRes[0][1]);
|
||||
- text: <code>ffr()</code>应返回<code>1509</code>
|
||||
testString: assert.equal(ffr(ffrParamRes[1][0]), ffrParamRes[1][1]);
|
||||
- text: <code>ffr()</code>应返回<code>5764</code>
|
||||
testString: assert.equal(ffr(ffrParamRes[2][0]), ffrParamRes[2][1]);
|
||||
- text: <code>ffr()</code>应返回<code>526334</code>
|
||||
testString: assert.equal(ffr(ffrParamRes[3][0]), ffrParamRes[3][1]);
|
||||
- text: <code>ffs()</code>应该返回<code>14</code>
|
||||
testString: assert.equal(ffs(ffsParamRes[0][0]), ffsParamRes[0][1]);
|
||||
- text: <code>ffs()</code>应该返回<code>59</code>
|
||||
testString: assert.equal(ffs(ffsParamRes[1][0]), ffsParamRes[1][1]);
|
||||
- text: <code>ffs()</code>应该返回<code>112</code>
|
||||
testString: assert.equal(ffs(ffsParamRes[2][0]), ffsParamRes[2][1]);
|
||||
- text: <code>ffs()</code>应该返回<code>1041</code>
|
||||
testString: assert.equal(ffs(ffsParamRes[3][0]), ffsParamRes[3][1]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// noprotect
|
||||
function ffr(n) {
|
||||
return n;
|
||||
}
|
||||
|
||||
function ffs(n) {
|
||||
return n;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,71 @@
|
||||
---
|
||||
title: Hofstadter Q sequence
|
||||
id: 59637c4d89f6786115efd814
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: Hofstadter Q序列
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p> <a href="https://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Q_sequence" title="wp:Hofstadter_sequence#Hofstadter_Q_sequence">Hofstadter Q序列</a>定义为: </p><p> $ Q(1)= Q(2)= 1,\\ Q(n)= Q \ big(nQ(n-1)\ big)+ Q \ big(nQ(n-2)),\ quad n> 2. $ </p><p>它定义为<a href="http://rosettacode.org/wiki/Fibonacci sequence" title="斐波那契序列">Fibonacci序列</a> ,但<a href="http://rosettacode.org/wiki/Fibonacci sequence" title="斐波那契序列">Fibonacci序列中</a>的下一个术语是前两个术语的总和,在Q序列中,前两个术语告诉您在Q序列中返回多远以找到两个数字总结以制作序列的下一个术语。 </p>任务:将Hofstadter Q Sequence方程实现为JavaScript </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>hofstadterQ</code>是一个函数。
|
||||
testString: assert(typeof hofstadterQ === 'function');
|
||||
- text: <code>hofstadterQ()</code>应该返回<code>integer</code>
|
||||
testString: assert(Number.isInteger(hofstadterQ(1000)));
|
||||
- text: <code>hofstadterQ(1000)</code>应该返回<code>502</code>
|
||||
testString: assert.equal(hofstadterQ(testCase[0]), res[0]);
|
||||
- text: <code>hofstadterQ(1500)</code>应该返回<code>755</code>
|
||||
testString: assert.equal(hofstadterQ(testCase[1]), res[1]);
|
||||
- text: <code>hofstadterQ(2000)</code>应该返回<code>1005</code>
|
||||
testString: assert.equal(hofstadterQ(testCase[2]), res[2]);
|
||||
- text: <code>hofstadterQ(2500)</code>应该返回<code>1261</code>
|
||||
testString: assert.equal(hofstadterQ(testCase[3]), res[3]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function hofstadterQ (n) {
|
||||
// Good luck!
|
||||
return n;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,66 @@
|
||||
---
|
||||
title: I before E except after C
|
||||
id: 5a23c84252665b21eecc7eb0
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 我在E之前除了C之后
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">短语<a href="https://en.wikipedia.org/wiki/I before E except after C">“我在E之前,除了C之后”</a>是一个广为人知的助记符,它应该有助于拼写英语单词。使用提供的单词,检查短语的两个子句是否合理: <ol><li style="margin-bottom: 5px;"> <i>“我在E之前没有前面的C”。</i> </li><li> <i>“在我之前的C之前是C”。</i> </li></ol>如果两个子短语都是合理的,则原始短语可以说是合理的。编写一个接受单词的函数,并检查单词是否遵循此规则。如果该函数遵循规则,则该函数应返回true,否则返回false。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>IBeforeExceptC</code>应该是一个函数。
|
||||
testString: assert(typeof IBeforeExceptC=='function');
|
||||
- text: <code>IBeforeExceptC("receive")</code>应该返回一个布尔值。
|
||||
testString: assert(typeof IBeforeExceptC("receive")=='boolean');
|
||||
- text: <code>IBeforeExceptC("receive")</code>应该返回<code>true</code> 。
|
||||
testString: assert.equal(IBeforeExceptC("receive"),true);
|
||||
- text: <code>IBeforeExceptC("science")</code>应该返回<code>false</code> 。
|
||||
testString: assert.equal(IBeforeExceptC("science"),false);
|
||||
- text: <code>IBeforeExceptC("imperceivable")</code>应该返回<code>true</code> 。
|
||||
testString: assert.equal(IBeforeExceptC("imperceivable"),true);
|
||||
- text: <code>IBeforeExceptC("inconceivable")</code>应该返回<code>true</code> 。
|
||||
testString: assert.equal(IBeforeExceptC("inconceivable"),true);
|
||||
- text: <code>IBeforeExceptC("insufficient")</code>应返回<code>false</code> 。
|
||||
testString: assert.equal(IBeforeExceptC("insufficient"),false);
|
||||
- text: <code>IBeforeExceptC("omniscient")</code>应该返回<code>false</code> 。
|
||||
testString: assert.equal(IBeforeExceptC("omniscient"),false);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function IBeforeExceptC (word) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,72 @@
|
||||
---
|
||||
title: IBAN
|
||||
id: 5a23c84252665b21eecc7eaf
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 他们
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <a href="https://en.wikipedia.org/wiki/International_Bank_Account_Number">国际银行账号(IBAN)</a>是一种国际商定的识别跨国界银行账户的方法,降低了传播<a href="https://en.wikipedia.org/wiki/Transcription_error">抄写错误的</a>风险。 IBAN最多包含34个字母数字字符: <ul><li>首先是两个字母的ISO 3166-1 alpha-2国家代码</li><li>然后是两个校验位,和</li><li>最后是国家特定的基本银行帐号(BBAN)。 </li></ul>通过检查数字,即使在提交交易之前,也可以对银行帐号进行健全性检查以确认其完整性。编写一个以IBAN字符串作为参数的函数。如果有效则返回true。否则,返回false。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>isValid</code>应该是一个函数。
|
||||
testString: assert(typeof isValid=='function');
|
||||
- text: <code>isValid(""+tests[0]+"")</code>应该返回一个布尔值。
|
||||
testString: assert(typeof isValid('GB82 WEST 1234 5698 7654 32')=='boolean');
|
||||
- text: <code>isValid(""+tests[0]+"")</code>应该返回<code>true</code> 。
|
||||
testString: assert.equal(isValid('GB82 WEST 1234 5698 7654 32'),true);
|
||||
- text: <code>isValid(""+tests[1]+"")</code>应返回<code>false</code> 。
|
||||
testString: assert.equal(isValid('GB82 WEST 1.34 5698 7654 32'),false);
|
||||
- text: <code>isValid(""+tests[2]+"")</code>应返回<code>false</code> 。
|
||||
testString: assert.equal(isValid('GB82 WEST 1234 5698 7654 325'),false);
|
||||
- text: <code>isValid(""+tests[3]+"")</code>应该返回<code>false</code> 。
|
||||
testString: assert.equal(isValid('GB82 TEST 1234 5698 7654 32'),false);
|
||||
- text: <code>isValid(""+tests[4]+"")</code>应该返回<code>true</code> 。
|
||||
testString: assert.equal(isValid('SA03 8000 0000 6080 1016 7519'),true);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function isValid (iban) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,70 @@
|
||||
---
|
||||
title: Identity matrix
|
||||
id: 5a23c84252665b21eecc7eb1
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 身份矩阵
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <i>单位矩阵</i>是大小为\(n \次n \)的方阵,其中对角元素都是<b>1</b> s(1),所有其他元素都是<b>0</b> s(零)。 \ begin {bmatrix} 1&0&0 \ cr 0&1&0 \ cr 0&0&1 \ cr \ end {bmatrix}编写一个以数字'n'作为参数并返回单位矩阵的函数订单nx n。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>idMatrix</code>应该是一个功能。
|
||||
testString: assert(typeof idMatrix=='function');
|
||||
- text: <code>idMatrix(1)</code>应该返回一个数组。
|
||||
testString: assert(Array.isArray(idMatrix(1)));
|
||||
- text: '<code>idMatrix(1)</code>应返回<code>"+JSON.stringify(results[0])+"</code> 。'
|
||||
testString: assert.deepEqual(idMatrix(1),results[0]);
|
||||
- text: '<code>idMatrix(2)</code>应返回<code>"+JSON.stringify(results[1])+"</code> 。'
|
||||
testString: assert.deepEqual(idMatrix(2),results[1]);
|
||||
- text: '<code>idMatrix(3)</code>应返回<code>"+JSON.stringify(results[2])+"</code> 。'
|
||||
testString: assert.deepEqual(idMatrix(3),results[2]);
|
||||
- text: '<code>idMatrix(4)</code>应返回<code>"+JSON.stringify(results[3])+"</code> 。'
|
||||
testString: assert.deepEqual(idMatrix(4),results[3]);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function idMatrix (n) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
title: Iterated digits squaring
|
||||
id: 5a23c84252665b21eecc7ec1
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 迭代的数字平方
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">如果添加自然数(大于零的整数)的数字的平方,则始终以1或89结尾: <pre> 15 - > 26 - > 40 - > 16 - > 37 - > 58 - > 89
|
||||
7 - > 49 - > 97 - > 130 - > 10 - > 1 </pre>编写一个函数,该函数将数字作为参数,并在执行上述过程后返回1或89。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>iteratedSquare</code>应该是一个函数。
|
||||
testString: assert(typeof iteratedSquare=='function');
|
||||
- text: <code>iteratedSquare(4)</code>应该返回一个数字。
|
||||
testString: assert(typeof iteratedSquare(4)=='number');
|
||||
- text: <code>iteratedSquare(4)</code>应该返回<code>89</code> 。
|
||||
testString: assert.equal(iteratedSquare(4),89);
|
||||
- text: <code>iteratedSquare(7)</code>应该返回<code>1</code> 。
|
||||
testString: assert.equal(iteratedSquare(7),1);
|
||||
- text: <code>iteratedSquare(15)</code>应该返回<code>89</code> 。
|
||||
testString: assert.equal(iteratedSquare(15),89);
|
||||
- text: <code>iteratedSquare(20)</code>应该返回<code>89</code> 。
|
||||
testString: assert.equal(iteratedSquare(20),89);
|
||||
- text: <code>iteratedSquare(70)</code>应该返回<code>1</code> 。
|
||||
testString: assert.equal(iteratedSquare(70),1);
|
||||
- text: <code>iteratedSquare(100)</code>应该返回<code>1</code> 。
|
||||
testString: assert.equal(iteratedSquare(100),1);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function iteratedSquare (n) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,72 @@
|
||||
---
|
||||
title: Jaro distance
|
||||
id: 5a23c84252665b21eecc7ec2
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: Jaro距离
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Jaro距离是两个弦之间相似性的度量。两个弦的Jaro距离越高,弦越相似。对得分进行归一化,使得<b>0</b>等于没有相似性, <b>1</b>等于完全匹配。定义两个给定字符串\(s_1 \)和\(s_2 \)的Jaro距离\(d_j \)是\ begin {align} d_j = \ begin {cases} 0 && \ text {if} m = 0 \\\ \ {\ frac {1} {3}} \ left({\ frac {m} {| s_ {1} |}} + {\ frac {m} {| s_ {2} |}} + {\ frac { mt} {m}} \ right)&& \ text {otherwise} \ end {cases} \ end {align}其中: <ul><li> \(m \)是<i>匹配字符</i>的数量; </li><li> \(t \)是<i>换位</i>次数的一半。 </li></ul>分别来自\(s_1 \)和\(s_2 \)的两个字符只有在相同且不远于\(\ left \ lfloor \ frac {\ max(| s_1 |,| s_2 |)}时才被认为是<i>匹配的</i> {2} \右\ rfloor-1 \)。将\(s_1 \)的每个字符与\(s_2 \)中的所有匹配字符进行比较。匹配(但不同的序列顺序)字符除以2的数量定义了<i>转置</i>的数量。 <b>示例</b>给定字符串\(s_1 \) <i>DWAYNE</i>和\(s_2 \) <i>DUANE</i>我们发现: <ul><li> \(m = 4 \) </li><li> \(| s_1 | = 6 \) </li><li> \(| s_2 | = 5 \) </li><li> \(t = 0 \) </li></ul>我们发现Jaro得分为:\(d_j = \ frac {1} {3} \ left(\ frac {4} {6} + \ frac {4} {5} + \ frac {4-0} {4} \ right)= 0.822 \)。编写一个函数a,它接受两个字符串作为参数并返回相关的Jaro距离。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>jaro</code>应该是一个功能。
|
||||
testString: assert(typeof jaro=='function');
|
||||
- text: <code>jaro(""+tests[0][0]+"",""+tests[0][1]+"")</code>应返回一个数字。
|
||||
testString: assert(typeof jaro('MARTHA', 'MARHTA')=='number');
|
||||
- text: <code>jaro(""+tests[0][0]+"",""+tests[0][1]+"")</code>应该返回<code>"+results[0]+"</code> 。
|
||||
testString: assert.equal(jaro('MARTHA', 'MARHTA'), 0.9444444444444445);
|
||||
- text: <code>jaro(""+tests[1][0]+"",""+tests[1][1]+"")</code>应返回<code>"+results[1]+"</code> 。
|
||||
testString: assert.equal(jaro('DIXON', 'DICKSONX'), 0.7666666666666666);
|
||||
- text: <code>jaro(""+tests[2][0]+"",""+tests[2][1]+"")</code>应返回<code>"+results[2]+"</code> 。
|
||||
testString: assert.equal(jaro('JELLYFISH', 'SMELLYFISH'), 0.8962962962962964);
|
||||
- text: <code>jaro(""+tests[3][0]+"",""+tests[3][1]+"")</code>应返回<code>"+results[3]+"</code> 。
|
||||
testString: assert.equal(jaro('HELLOS', 'CHELLO'), 0.888888888888889);
|
||||
- text: <code>jaro(""+tests[4][0]+"",""+tests[4][1]+"")</code>应该返回<code>"+results[4]+"</code> 。
|
||||
testString: assert.equal(jaro('ABCD', 'BCDA'), 0.8333333333333334);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function jaro (s, t) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,74 @@
|
||||
---
|
||||
title: JortSort
|
||||
id: 5a23c84252665b21eecc7ec4
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: JortSort
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> jortSort是一个排序工具集,它使用户可以完成工作并保证效率,因为您不必再次排序。它最初是由着名的<a href="https://www.youtube.com/watch?v=pj4U_W0OFoE">JSConf的</a> Jenn“Moneydollars”Schiffer <a href="https://www.youtube.com/watch?v=pj4U_W0OFoE">提出的</a> 。 jortSort是一个函数,它将一个可比较对象数组作为其参数。然后它按升序对数组进行排序,并将排序后的数组与最初提供的数组进行比较。如果数组匹配(即原始数组已经排序),则该函数返回true。如果数组不匹配(即原始数组未排序),则该函数返回false。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>jortsort</code>应该是一个功能。
|
||||
testString: assert(typeof jortsort=='function');
|
||||
- text: '<code>jortsort("+JSON.stringify(tests[0])+")</code>应该返回一个布尔值。'
|
||||
testString: assert(typeof jortsort([1,2,3,4,5])=='boolean');
|
||||
- text: '<code>jortsort("+JSON.stringify(tests[0])+")</code>应该返回<code>true</code> 。'
|
||||
testString: assert.equal(jortsort([1,2,3,4,5]),true);
|
||||
- text: '<code>jortsort("+JSON.stringify(tests[1])+")</code>应该返回<code>false</code> 。'
|
||||
testString: assert.equal(jortsort([1,2,13,4,5]),false);
|
||||
- text: '<code>jortsort("+JSON.stringify(tests[2])+")</code>应该返回<code>false</code> 。'
|
||||
testString: assert.equal(jortsort([12,4,51,2,4]),false);
|
||||
- text: '<code>jortsort("+JSON.stringify(tests[3])+")</code>应该返回<code>true</code> 。'
|
||||
testString: assert.equal(jortsort([1,2]),true);
|
||||
- text: '<code>jortsort("+JSON.stringify(tests[4])+")</code>应该返回<code>false</code> 。'
|
||||
testString: assert.equal(jortsort([5,4,3,2,1]),false);
|
||||
- text: '<code>jortsort("+JSON.stringify(tests[5])+")</code>应该返回<code>true</code> 。'
|
||||
testString: assert.equal(jortsort([1,1,1,1,1]),true);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function jortsort (array) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,64 @@
|
||||
---
|
||||
title: Josephus problem
|
||||
id: 5a23c84252665b21eecc7ec5
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 约瑟夫斯问题
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <a href="https://en.wikipedia.org/wiki/Josephus problem">约瑟夫斯问题</a>是一个严峻描述的数学难题:$ n $囚犯站在一个圆圈上,顺序编号从$ 0 $到$ n-1 $。一名刽子手沿着圈子走,从囚犯$ 0 $开始,移走每个$ k $囚犯并杀死他。随着过程的继续,圆圈变得越来越小,直到只剩下一个囚犯,然后被释放。例如,如果$ n = 5 $囚犯和$ k = 2 $,囚犯被杀的命令(我们称之为“杀戮序列”)将是1,3,0和4,幸存者将是#2。鉴于任何<big>$ n,k> 0 $</big> ,找出哪个囚犯将成为最后的幸存者。在一个这样的事件中,有41个囚犯和每3 <sup>次</sup>囚犯被杀死<big>($ K = 3 $)。</big>其中有一个聪明的名字约瑟夫斯,他解决了这个问题,站在幸存的位置,并继续讲述这个故事。他是哪个号码?写一个函数,以囚犯的初始数量和'k'作为参数,并返回幸存的囚犯的数量。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>josephus</code>应该是一个功能。
|
||||
testString: assert(typeof josephus=='function');
|
||||
- text: '<code>josephus(30,3)</code>应该返回一个数字。'
|
||||
testString: assert(typeof josephus(30,3)=='number');
|
||||
- text: '<code>josephus(30,3)</code>应该回<code>29</code> 。'
|
||||
testString: assert.equal(josephus(30,3),29);
|
||||
- text: '<code>josephus(30,5)</code>应该返回<code>3</code> 。'
|
||||
testString: assert.equal(josephus(30,5),3);
|
||||
- text: '<code>josephus(20,2)</code>应该返回<code>9</code> 。'
|
||||
testString: assert.equal(josephus(20,2),9);
|
||||
- text: '<code>josephus(17,6)</code>应该回归<code>2</code> 。'
|
||||
testString: assert.equal(josephus(17,6),2);
|
||||
- text: '<code>josephus(29,4)</code>应该返回<code>2</code> 。'
|
||||
testString: assert.equal(josephus(29,4),2);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function josephus (init, kill) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
title: S-Expressions
|
||||
id: 59667989bf71cf555dd5d2ff
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: S-表达式
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p> <a href="https://en.wikipedia.org/wiki/S-Expression" title="wp:S表达式">S-Expressions</a>是一种解析和存储数据的便捷方式。 </p>任务: <p>为S-Expressions编写一个简单的读取器/解析器,处理引用的和不带引号的字符串,整数和浮点数。 </p><p>该函数应从字符串中读取单个但嵌套的S-Expression,并将其作为(嵌套)数组返回。 </p><p>除非包含在带引号的字符串中,否则可以忽略换行符和其他空格。 </p><p> “ <tt>()</tt> ”内部引用的字符串不会被解释,但会被视为字符串的一部分。 </p><p>处理字符串中的转义引号是可选的;因此“ <tt>(foo”bar)</tt> “可能被视为字符串” <tt>foo“bar</tt> ”,或作为错误。 </p><p>为此,读者无需识别“ <tt>\</tt> ”以进行转义,但如果语言具有适当的数据类型,则还应识别数字。 </p><p>请注意,除了“ <tt>()”</tt> “(” <tt>\</tt> “,如果支持转义)和空格,没有特殊字符。其他任何内容都是允许的,不带引号。 </p><p>读者应该能够阅读以下输入</p><p></p><pre> ((数据“引用数据”123 4.5)
|
||||
(数据(!@#(4.5)“(更多”“数据”))))
|
||||
</pre><p></p><p>并将其转换为本机数据结构。 (有关本机数据结构的示例,请参阅<a href="http://rosettacode.org/wiki/#Pike" title="#Pike">Pike</a> , <a href="http://rosettacode.org/wiki/#Python" title="#蟒蛇">Python</a>和<a href="http://rosettacode.org/wiki/#Ruby" title="#红宝石">Ruby</a>实现。) </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>parseSexpr</code>是一个函数。
|
||||
testString: assert(typeof parseSexpr === 'function');
|
||||
- text: <code>parseSexpr("(data1 data2 data3)")</code>应返回[“data1”,“data2”,“data3”]“)
|
||||
testString: assert.deepEqual(parseSexpr(simpleSExpr), simpleSolution);
|
||||
- text: <code>parseSexpr("(data1 data2 data3)")</code>应该返回一个包含3个元素的数组“)'
|
||||
testString: assert.deepEqual(parseSexpr(basicSExpr), basicSolution);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function parseSexpr(str) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,60 @@
|
||||
---
|
||||
title: 'Sailors, coconuts and a monkey problem'
|
||||
id: 59da22823d04c95919d46269
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 水手,椰子和猴子问题
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>五名水手在岛上遭遇海难,并在白天收集了一大堆椰子。 </p><p>那天晚上,第一个水手醒来并决定早点拿走他的第一份,所以试图将一堆椰子平分成五堆,但发现剩下一个椰子,所以他把它扔到一只猴子然后隐藏“他的”五个同样大小的椰子堆中的一个,并将其他四个桩推到一起,再次形成一堆可见的椰子并上床睡觉。 </p><p>长话短说,每个水手轮流在夜间起床,并执行将椰子堆分成五个的相同动作,发现剩下一个椰子并将剩下的椰子留给猴子。 </p><p>在早上(在夜间五个水手的暗中和分开行动之后),剩下的椰子被分成五个相等的堆,每个水手,然后发现一堆椰子在水手之间平分没有余数。 (早上猴子没什么。) </p><p>任务: </p><pre> <code> Create a function that returns the the minimum possible size of the initial pile of coconuts collected during the day for N sailors.</code> </pre><p>注意: </p><pre> <code> Of course the tale is told in a world where the collection of any amount of coconuts in a day and multiple divisions of the pile, etc can occur in time fitting the story line, so as not to affect the mathematics.</code> </pre><p> CF卡: </p><p> <a href="https://www.youtube.com/watch?v=U9qU20VmvaU" title="链接:https://www.youtube.com/watch?v = U9qU20VmvaU">猴子和椰子 - Numberphile</a> (视频)分析解决方案。 </p><pre> <code> <a href="http://oeis.org/A002021" title="link: http://oeis.org/A002021">A002021 Pile of coconuts problem</a> The On-Line Encyclopedia of Integer Sequences. (Although some of its references may use the alternate form of the tale).</code> </pre></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>splitCoconuts</code>是一个函数。
|
||||
testString: assert(typeof splitCoconuts === 'function');
|
||||
- text: <code>splitCoconuts(5)</code>应该返回3121。
|
||||
testString: assert(splitCoconuts(5) === 3121);
|
||||
- text: <code>splitCoconuts(6)</code>应返回233275。
|
||||
testString: assert(splitCoconuts(6) === 233275);
|
||||
- text: <code>splitCoconuts(7)</code>应该返回823537。
|
||||
testString: assert(splitCoconuts(7) === 823537);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// noprotect
|
||||
function splitCoconuts(intSailors) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,61 @@
|
||||
---
|
||||
title: SEDOLs
|
||||
id: 59d9c6bc214c613ba73ff012
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: SEDOLs
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>对于6位<a href="https://en.wikipedia.org/wiki/SEDOL" title="wp:SEDOL">SEDOL</a>的每个数字列表,计算并附加校验和数字。 </p><p>也就是说,给定左侧的输入字符串,您的函数应返回右侧的相应字符串: </p><pre> <code><pre> 710889 => 7108899 B0YBKJ => B0YBKJ7 406566 => 4065663 B0YBLH => B0YBLH2 228276 => 2282765 B0YBKL => B0YBKL9 557910 => 5579107 B0YBKR => B0YBKR5 585284 => 5852842 B0YBKT => B0YBKT7 B00030 => B000300 </pre></code> </pre><p>还要检查每个输入是否正确形成,尤其是对于SEDOL字符串中允许的有效字符。您的函数应在无效输入时返回<code>null</code> 。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>sedol</code>是一个功能。
|
||||
testString: assert(typeof sedol === 'function');
|
||||
- text: <code>sedol('a')</code>应该返回null。
|
||||
testString: assert(sedol('a') === null);
|
||||
- text: <code>sedol('710889')</code>应返回'7108899'。
|
||||
testString: assert(sedol('710889') === '7108899');
|
||||
- text: <code>sedol('BOATER')</code>应该返回null。
|
||||
testString: assert(sedol('BOATER') === null);
|
||||
- text: <code>sedol('228276')</code>应该返回'228276'。
|
||||
testString: assert(sedol('228276') === '2282765');
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function sedol (input) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,71 @@
|
||||
---
|
||||
title: Taxicab numbers
|
||||
id: 594ecc0d9a8cf816e3340187
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 出租车号码
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <a href="https://en.wikipedia.org/wiki/Hardy–Ramanujan number" title="wp:Hardy-Ramanujan号码">出租车编号</a> (此处使用的定义)是一个正整数,可以用多种方式表示为两个正立方体的总和。第一个出租车编号是1729,即:1 <sup>3</sup> + 12 <sup>3</sup>和9 <sup>3</sup> + 10 <sup>3</sup> 。出租车号码也被称为:*出租车号码*出租车号码*出租车号码* Hardy-Ramanujan号码任务:编写一个返回最低N个出租车号码的函数。对于每个出租车编号,显示数字以及它的构成立方体。另请参阅:在线整数序列百科全书上的[http://oeis.org/A001235 A001235出租车编号]。 MathWorld上的<a href="http://mathworld.wolfram.com/Hardy-RamanujanNumber.html">Hardy-Ramanujan数字</a> 。 MathWorld上的<a href="http://mathworld.wolfram.com/TaxicabNumber.html">出租车编号</a> 。维基百科上的<a href="https://en.wikipedia.org/wiki/Taxicab_number">出租车号码</a> 。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>taxicabNumbers</code>是一个功能。
|
||||
testString: assert(typeof taxicabNumbers === 'function');
|
||||
- text: <code>taxicabNumbers</code>应该返回一个数组。
|
||||
testString: assert(typeof taxicabNumbers(2) === 'object');
|
||||
- text: <code>taxicabNumbers</code>应返回一组数字。
|
||||
testString: assert(typeof taxicabNumbers(100)[0] === 'number');
|
||||
- text: '<code>taxicabNumbers(4)</code>必须返回[1729,4104,13832,20683]。'
|
||||
testString: assert.deepEqual(taxicabNumbers(4), res4);
|
||||
- text: 'taxicabNumbers(25)应该返回[1729,4104,13832,20683,32832,39312,40033,46683,64232,65728,110656,110808,134379,149389,165464,171288,195841,216027,216125,262656,314696,320264 ,327763,373464,402597]'
|
||||
testString: assert.deepEqual(taxicabNumbers(25), res25);
|
||||
- text: 'taxicabNumbers(39)由20 - 29得到的数字应为[314496,320264,327763,373464,402597,439101,443889,513000,513856]。'
|
||||
testString: assert.deepEqual(taxicabNumbers(39).slice(20, 29), res39From20To29);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function taxicabNumbers (n) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
title: Tokenize a string with escaping
|
||||
id: 594faaab4e2a8626833e9c3d
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 使用转义标记字符串
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>编写一个函数或程序,可以在分隔符的每个非转义事件中拆分字符串。 </p><p>它应该接受三个输入参数: </p> <b>字符串</b> <b>分隔符字符</b> <b>转义字符</b> <p>它应该输出一个字符串列表。 </p><p>拆分规则: </p>由分隔符分隔的字段将成为输出列表的元素。应保留空字段,即使在开始和结束时也是如此。 <p>转义规则: </p> “Escaped”意味着出现一个尚未自行转义的转义字符。当转义字符位于没有特殊含义的字符之前时,它仍然被视为转义符(但不会做任何特殊操作)。用于转义某些内容的每次出现的转义字符都不应成为输出的一部分。 <p>证明您的函数满足以下测试用例:给定字符串</p><pre>一个^ | UNO || 3 ^^^^ |四^^^ | ^夸| </pre>和使用<pre> | </pre>作为分隔符和<pre> ^ </pre>作为转义字符,您的函数应输出以下数组: <p></p><pre> ['one | uno',“,'three ^^','four ^ | quatro',”]
|
||||
</pre></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>tokenize</code>是一个函数。
|
||||
testString: assert(typeof tokenize === 'function');
|
||||
- text: <code>tokenize</code>应该返回一个数组。
|
||||
testString: assert(typeof tokenize('a', 'b', 'c') === 'object');
|
||||
- text: <code>tokenize("one^|uno||three^^^^|four^^^|^cuatro|", "|", "^")</code>应返回[“one | uno”,“”,“three ^^” ,“四个^ | cuatro”,“”]“)
|
||||
testString: assert.deepEqual(tokenize(testStr1, '|', '^'), res1);
|
||||
- text: '<code>tokenize("a@&bcd&ef&&@@hi", "&", "@")</code>应返回<code>["a&bcd", "ef", "", "@hi"]</code>'
|
||||
testString: assert.deepEqual(tokenize(testStr2, '&', '@'), res2);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function tokenize(str, esc, sep) {
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,95 @@
|
||||
---
|
||||
title: Top rank per group
|
||||
id: 595011cba5a81735713873bd
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 每组排名最高
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>在每个组中查找排名前N位的数据,其中N作为参数提供。等级和组的名称也作为参数提供。 </p>鉴于以下数据: <pre> [
|
||||
{姓名:'Tyler Bennett',id:'E10297',薪水:32000,部门:'D101'},
|
||||
{姓名:'John Rappl',id:'E21437',薪水:47000,部门:'D050'},
|
||||
{姓名:'George Woltman',id:'E00127',薪水:53500,部门:'D101'},
|
||||
{name:'Adam Smith',id:'E63535',薪水:18000,部门:'D202'},
|
||||
{姓名:'Claire Buckman',id:'E39876',薪水:27800,部门:'D202'},
|
||||
{姓名:'David McClellan',id:'E04242',薪水:41500,部门:'D101'},
|
||||
{name:'Rich Holcomb',id:'E01234',薪水:49500,dept:'D202'},
|
||||
{姓名:'Nathan Adams',id:'E41298',薪水:21900,部门:'D050'},
|
||||
{姓名:'Richard Potter',id:'E43128',薪水:15900,部门:'D101'},
|
||||
{姓名:'David Motsinger',id:'E27002',薪水:19250,dept:'D202'},
|
||||
{姓名:'Tim Sampair',id:'E03033',薪水:27000,部门:'D101'},
|
||||
{姓名:'Kim Arlich',id:'E10001',薪水:57000,部门:'D190'},
|
||||
{name:'Timothy Grove',id:'E16398',薪水:29900,部门:'D190'}
|
||||
]。
|
||||
</pre>通过调用<code>topRankPerGroup(10, data, 'dept', 'salary')</code>可以对每个部门的前10名员工进行排名。给出以下数据: <pre> [
|
||||
{name:'Friday 13th',类型:'恐怖',评分:9.9},
|
||||
{姓名:“榆树街上的梦魇”,类型:'恐怖',等级:5.7},
|
||||
{name:'Titanic',类型:'drama',评分:7.3},
|
||||
{name:'Maze Runner',类型:'scifi',评级:7.1},
|
||||
{name:'Blade runner',类型:'scifi',评分:8.9}
|
||||
]。
|
||||
</pre>通过调用<code>topRankPerGroup(1, data, 'genre', 'rating')</code>可以在每个类型中对排名最高的电影进行排名</section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>topRankPerGroup</code>是一个函数。
|
||||
testString: assert(typeof topRankPerGroup === 'function');
|
||||
- text: <code>topRankPerGroup</code>在负n值上返回undefined。
|
||||
testString: assert(typeof topRankPerGroup(-1, []) === 'undefined');
|
||||
- text: 第一部门必须是D050
|
||||
testString: assert.equal(res1[0][0].dept, 'D050');
|
||||
- text: 第一部门必须是D050
|
||||
testString: assert.equal(res1[0][1].salary, 21900);
|
||||
- text: 最后一个部门必须是D202
|
||||
testString: assert.equal(res1[3][3].dept, 'D202');
|
||||
- text: '<code>topRankPerGroup(1, ...)</code>必须仅返回每组的排名最高的结果。'
|
||||
testString: assert.equal(res2[2].length, 1);
|
||||
- text: '<code>topRankPerGroup(1, ...)</code>必须仅返回每组的排名最高的结果。'
|
||||
testString: assert.equal(res3[2][1].name, 'Maze Runner');
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function topRankPerGroup(n, data, groupName, rankName) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,84 @@
|
||||
---
|
||||
title: Topological sort
|
||||
id: 594fa2746886f41f7d8bf225
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 拓扑排序
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>给定项目之间的映射以及它们所依赖的项目, <a href="https://en.wikipedia.org/wiki/Topological sorting" title="wp:拓扑排序">拓扑排序</a>会对项目进行<a href="https://en.wikipedia.org/wiki/Topological sorting" title="wp:拓扑排序">排序</a> ,以使项目不在其所依赖的项目之前。 </p><p>用<a href="https://en.wikipedia.org/wiki/VHDL" title="wp:VHDL">VHDL</a>语言编译库有一个限制,即必须在它依赖的库之后编译库。 </p>任务: <p>编写一个函数,该函数将从其依赖项返回VHDL库的有效编译顺序。 </p>假设库名称是单个单词。仅作为家属提及的项目没有自己的家属,但必须给出他们的编制顺序。任何自我依赖都应该被忽略。应忽略任何不可订购的依赖项。 <p>使用以下数据作为示例: </p><pre>图书馆图书馆依赖
|
||||
======= ====================
|
||||
des_system_lib std synopsys std_cell_lib des_system_lib dw02 dw01 ramlib ieee
|
||||
dw01 ieee dw01 dware gtech
|
||||
dw02 ieee dw02 dware
|
||||
dw03 std synopsys dware dw03 dw02 dw01 ieee gtech
|
||||
dw04 dw04 ieee dw01 dware gtech
|
||||
dw05 dw05 ieee dware
|
||||
dw06 dw06 ieee dware
|
||||
dw07 ieee dware
|
||||
dware ieee dware
|
||||
gtech ieee gtech
|
||||
ramlib std ieee
|
||||
std_cell_lib ieee std_cell_lib
|
||||
新思
|
||||
</pre><p> <small>注意:如果将<code>dw04</code>添加到<code>dw01</code>的依赖项列表中,则上述数据将无法订购。</small> </p> CF卡: <pre> <code><a href="http://rosettacode.org/wiki/Topological sort/Extracted top item" title="Topological sort/Extracted top item">Topological sort/Extracted top item</a>.</code> </pre><p>拓扑排序有两种流行的算法: </p><p> Kahn的1962拓扑排序和深度优先搜索: <a href="https://en.wikipedia.org/wiki/Topological sorting" title="wp:拓扑排序">拓扑排序</a> </p><p> Jason Sachs: <a href="http://www.embeddedrelated.com/showarticle/799.php" title="链接:http://www.embeddedrelated.com/showarticle/799.php">“十个小算法,第四部分:拓扑排序”</a> 。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>topologicalSort</code>是一个函数。
|
||||
testString: assert(typeof topologicalSort === 'function');
|
||||
- text: <code>topologicalSort</code>必须返回正确的库顺序..
|
||||
testString: assert.deepEqual(topologicalSort(libsSimple), ['bbb', 'aaa']);
|
||||
- text: <code>topologicalSort</code>必须返回正确的库顺序..
|
||||
testString: assert.deepEqual(topologicalSort(libsVHDL), solutionVHDL);
|
||||
- text: <code>topologicalSort</code>必须返回正确的库顺序..
|
||||
testString: assert.deepEqual(topologicalSort(libsCustom), solutionCustom);
|
||||
- text: <code>topologicalSort</code>必须忽略不可共享的依赖项。
|
||||
testString: assert.deepEqual(topologicalSort(libsUnorderable), solutionUnorderable);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function topologicalSort(libs) {
|
||||
// Good luck!
|
||||
return true;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,69 @@
|
||||
---
|
||||
title: Towers of Hanoi
|
||||
id: 5951ed8945deab770972ae56
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 河内的塔
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">任务: <p>解决<a href="https://en.wikipedia.org/wiki/Towers_of_Hanoi" title="wp:Towers_of_Hanoi">河内塔</a>问题。 </p><p>您的解决方案应该接受光盘数量作为第一个参数,并使用三个字符串来识别三个光盘堆栈中的每一个,例如<code>towerOfHanoi(4, 'A', 'B', 'C')</code> 。该函数应该返回一个包含移动列表的数组数组,source - > destination。例如,数组<code>[['A', 'C'], ['B', 'A']]</code>表示第一个移动是将光盘从堆栈A移动到C,第二个移动是移动一个从堆栈B到A的光盘</p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>towerOfHanoi</code>是一个功能。
|
||||
testString: assert(typeof towerOfHanoi === 'function');
|
||||
- text: <code>towerOfHanoi(3, ...)</code> 应该返回7招。
|
||||
testString: assert(res3.length === 7);
|
||||
- text: <code>towerOfHanoi(3, "A", "B", "C")</code>应返回[[“A”,“B”],[“A”,“C”],[“B”,“C”],[ “A”, “B”],[ “C”, “A”],[ “C”, “B”],[ “A”, “B”]]“)。
|
||||
testString: assert.deepEqual(towerOfHanoi(3, 'A', 'B', 'C'), res3Moves);
|
||||
- text: <code>towerOfHanoi(5, "X", "Y", "Z")</code>第10 <code>towerOfHanoi(5, "X", "Y", "Z")</code>应为Y - > X.
|
||||
testString: assert.deepEqual(res5[9], ['Y', 'X']);
|
||||
- text: <code>towerOfHanoi(7, "A", "B", "C")</code>前十个动作是[[“A”,“B”],[“A”,“C”],[“B”,“C”] [ “A”, “B”],[ “C”, “A”],[ “C”, “B”],[ “A”, “B”],[ “A”, “C”] [ “B”, “C”],[ “B”, “A”]]“)。
|
||||
testString: assert.deepEqual(towerOfHanoi(7, 'A', 'B', 'C').slice(0, 10), res7First10Moves);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function towerOfHanoi (n, a, b, c) {
|
||||
// Good luck!
|
||||
return [[]];
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,64 @@
|
||||
---
|
||||
title: Vector cross product
|
||||
id: 594810f028c0303b75339ad2
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 矢量交叉产品
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">矢量被定义为具有三个维度,由三个数字的有序集合表示:(X,Y,Z)。 <p>任务: </p><pre> <code>Write a function that takes two vectors (arrays) as input and computes their cross product.</code> </pre><p>您的函数应在无效输入(即不同长度的向量)上返回<code>null</code> 。 </p><p></p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: dotProduct必须是一个函数
|
||||
testString: assert.equal(typeof crossProduct, 'function');
|
||||
- text: dotProduct()必须返回null
|
||||
testString: assert.equal(crossProduct(), null);
|
||||
- text: 'crossProduct([1,2,3],[4,5,6])必须返回[-3,6,-3]。'
|
||||
testString: assert.deepEqual(res12, exp12);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function crossProduct() {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,62 @@
|
||||
---
|
||||
title: Vector dot product
|
||||
id: 594810f028c0303b75339ad3
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 矢量点积
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>矢量被定义为具有三个维度,由三个数字的有序集合表示:(X,Y,Z)。 </p><p>任务: </p><pre> <code>Write a function that takes any numbers of vectors (arrays) as input and computes their dot product.</code> </pre><p>您的函数应在无效输入(即不同长度的向量)上返回<code>null</code> 。 </p><p></p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: dotProduct必须是一个函数
|
||||
testString: assert.equal(typeof dotProduct, 'function');
|
||||
- text: dotProduct()必须返回null
|
||||
testString: assert.equal(dotProduct(), null);
|
||||
- text: 'dotProduct([[1],[1]])必须返回1。'
|
||||
testString: assert.equal(dotProduct([1], [1]), 1);
|
||||
- text: 'dotProduct([[1],[1,2]])必须返回null。'
|
||||
testString: assert.equal(dotProduct([1], [1, 2]), null);
|
||||
- text: 'dotProduct([1,3,-5],[4,-2,-1])必须返回3。'
|
||||
testString: assert.equal(dotProduct([1, 3, -5], [4, -2, -1]), 3);
|
||||
- text: <code>dotProduct(...nVectors)</code>应该返回<code>dotProduct(...nVectors)</code>
|
||||
testString: assert.equal(dotProduct([ 0, 1, 2, 3, 4 ], [ 0, 2, 4, 6, 8 ], [ 0, 3, 6, 9, 12 ], [ 0, 4, 8, 12, 16 ], [ 0, 5, 10, 15, 20 ]), 156000);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function dotProduct() {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,78 @@
|
||||
---
|
||||
title: Word wrap
|
||||
id: 594810f028c0303b75339ad4
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 自动换行
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>即使在今天,使用比例字体和复杂布局,仍然存在需要在指定列处包装文本的情况。基本任务是以简单的方式包装一段文本。示例文字: </p><pre>使用更复杂的算法(如Knuth和Plass TeX算法)包装文本。
|
||||
如果您的语言提供此功能,您可以获得额外的信用,
|
||||
但你“必须参考文档”表明该算法
|
||||
比简单的最小长度算法更好。
|
||||
</pre><p>任务: </p><pre> <code>Write a function that can wrap this text to any number of characters.</code> </pre><p>例如,包装为80个字符的文本应如下所示: </p><p></p><pre>使用更复杂的算法(如Knuth和Plass TeX)包装文本
|
||||
算法。如果您的语言提供此功能,您可以轻松获得额外的功劳
|
||||
必须参考文档,表明该算法更好
|
||||
而不是简单的最小长度算法。
|
||||
</pre></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>wrap</code>是一个功能。
|
||||
testString: assert.equal(typeof wrap, 'function');
|
||||
- text: <code>wrap("abc", 10)</code>必须返回一个字符串。
|
||||
testString: assert.equal(typeof wrap('abc', 10), 'string');
|
||||
- text: wrap(80)必须返回4行。
|
||||
testString: assert(wrapped80.split('\n').length === 4);
|
||||
- text: 你的<code>wrap</code>函数应该返回我们期望的文本
|
||||
testString: assert.equal(wrapped80.split('\n')[0], firstRow80);
|
||||
- text: wrap(42)必须返回7行。
|
||||
testString: assert(wrapped42.split('\n').length === 7);
|
||||
- text: 你的<code>wrap</code>函数应该返回我们期望的文本
|
||||
testString: assert.equal(wrapped42.split('\n')[0], firstRow42);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function wrap (text, limit) {
|
||||
return text;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,78 @@
|
||||
---
|
||||
title: Y combinator
|
||||
id: 594810f028c0303b75339ad5
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 和组合
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>在严格的<a href="https://en.wikipedia.org/wiki/Functional programming" title="wp:函数式编程">函数编程</a>和<a href="https://en.wikipedia.org/wiki/lambda calculus" title="wp:lambda演算">lambda演算中</a> ,函数(lambda表达式)没有状态,只允许引用封闭函数的参数。这排除了递归函数的通常定义,其中函数与变量的状态相关联,并且该变量的状态在函数体中使用。 </p><p> <a href="http://mvanier.livejournal.com/2897.html">Y组合</a>器本身是一个无状态函数,当应用于另一个无状态函数时,它返回函数的递归版本。 Y组合器是这类函数中最简单的一种,称为<a href="https://en.wikipedia.org/wiki/Fixed-point combinator" title="wp:定点组合器">定点组合器</a> 。 </p>任务: <pre> <code>Define the stateless Y combinator function and use it to compute <a href="https://en.wikipedia.org/wiki/Factorial" title="wp: factorial">factorial</a>.</code> </pre><p> <code>factorial(N)</code>功能已经给你了。另见<a href="http://vimeo.com/45140590">Jim Weirich:功能编程中的冒险</a> 。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Y必须返回一个函数
|
||||
testString: assert.equal(typeof Y(f => n => n), 'function');
|
||||
- text: factorial(1)必须返回1。
|
||||
testString: assert.equal(factorial(1), 1);
|
||||
- text: factorial(2)必须返回2。
|
||||
testString: assert.equal(factorial(2), 2);
|
||||
- text: factorial(3)必须返回6。
|
||||
testString: assert.equal(factorial(3), 6);
|
||||
- text: factorial(4)必须返回24。
|
||||
testString: assert.equal(factorial(4), 24);
|
||||
- text: factorial(10)必须返回3628800。
|
||||
testString: assert.equal(factorial(10), 3628800);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function Y(f) {
|
||||
return function() {
|
||||
// Good luck!
|
||||
};
|
||||
}
|
||||
|
||||
var factorial = Y(function(f) {
|
||||
return function (n) {
|
||||
return n > 1 ? n * f(n - 1) : 1;
|
||||
};
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,62 @@
|
||||
---
|
||||
title: Zeckendorf number representation
|
||||
id: 594810f028c0303b75339ad6
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 勾选村号码表示
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"><p>正如数字可以用位置表示法表示为十(十进制)或二(二进制)的幂的倍数之和;所有正整数都可以表示为Fibonacci系列的不同成员的一次或零次的总和。 </p><p>回想一下,第一六个不同斐波那契数是: <code>1, 2, 3, 5, 8, 13</code> 。十进制数11可以用位置表示法写成<code>0*13 + 1*8 + 0*5 + 1*3 + 0*2 + 0*1</code>或<code>010100</code> ,其中列表示乘以序列的特定成员。前导零被丢弃,因此十进制11变为<code>10100</code> 。 </p><p> 10100不是从斐波那契数字中得到11的唯一方法,但是<code>0*13 + 1*8 + 0*5 + 0*3 + 1*2 + 1*1</code>或010011也代表十进制11。对于真正的Zeckendorf数字还有一个额外的限制,即“不能使用两个连续的Fibonacci数”,这导致了前一个独特的解决方案。 </p><p>任务:编写一个函数,按顺序生成并返回前N个Zeckendorf数的数组。 </p></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: zeckendorf必须是功能
|
||||
testString: assert.equal(typeof zeckendorf, 'function');
|
||||
- text: 你的<code>zeckendorf</code>函数应该返回正确的答案
|
||||
testString: assert.deepEqual(answer, solution20);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function zeckendorf(n) {
|
||||
// good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,136 @@
|
||||
---
|
||||
title: Zhang-Suen thinning algorithm
|
||||
id: 594810f028c0303b75339ad7
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 张素细化算法
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description">这是用于稀释黑白的算法,即每像素一位图像。例如,输入图像为: <pre> ##############################
|
||||
##################################
|
||||
#####################################
|
||||
##################################
|
||||
###### ####### ####### ######
|
||||
###### ####### #######
|
||||
########################
|
||||
#######################
|
||||
########################
|
||||
###### ####### #######
|
||||
###### ####### #######
|
||||
###### ####### ####### ######
|
||||
##################################
|
||||
######## #####################################
|
||||
######## ###################################
|
||||
######## ####### ###### ###################
|
||||
</pre>它产生稀疏的输出: <pre>
|
||||
<pre> <code># ########## ####### ## # #### # # # ## # # # # # # # # # ############ # # # # # # # # # # # # # # ## # ############ ### ### </pre></code> </pre>
|
||||
<h2>算法</h2>
|
||||
假设黑色像素是一个并且白色像素为零,并且输入图像是矩形N乘M的1和0阵列。
|
||||
该算法对可以具有八个邻居的所有黑色像素P1进行操作。邻居按顺序安排为:
|
||||
<table border="1">
|
||||
<tbody><tr><td> P9 </td><td> P2 </td><td> P3 </td></tr>
|
||||
<tr><td> P8 </td><td> <b>P1</b> </td><td> P4 </td></tr>
|
||||
<tr><td> P7 </td><td> P6 </td><td> P5 </td></tr>
|
||||
</tbody></table>
|
||||
显然,图像的边界像素不能具有完整的八个邻居。
|
||||
<pre> <code>Define $A(P1)$ = the number of transitions from white to black, (0 -> 1) in the sequence P2,P3,P4,P5,P6,P7,P8,P9,P2. (Note the extra P2 at the end - it is circular). Define $B(P1)$ = the number of black pixel neighbours of P1. ( = sum(P2 .. P9) )</code> </pre>
|
||||
<h3>步骤1: </h3>
|
||||
测试所有像素,并且在此阶段仅注意满足以下所有条件(同时)的像素。
|
||||
(0)像素是黑色的,有八个邻居
|
||||
(1)$ 2 <= B(P1)<= 6 $
|
||||
(2)$ A(P1)= 1 $
|
||||
(3)P2和P4和P6中的至少一个是白色
|
||||
(4)P4和P6和P8中的至少一个是白色
|
||||
在迭代图像并收集满足所有步骤1条件的所有像素之后,将满足像素的所有这些条件设置为白色。
|
||||
<h3>第2步: </h3>
|
||||
再次测试所有像素,并且在此阶段仅注意满足以下所有条件的像素。
|
||||
(0)像素是黑色的,有八个邻居
|
||||
(1)$ 2 <= B(P1)<= 6 $
|
||||
(2)$ A(P1)= 1 $
|
||||
(3)P2和P4中的至少一个和“'P8”'是白色的
|
||||
(4)“'P2”'和P6和P8中的至少一个是白色
|
||||
在迭代图像并收集满足所有步骤2条件的所有像素之后,将满足像素的所有这些条件再次设置为白色。
|
||||
迭代:
|
||||
如果在该轮步骤1或步骤2中设置了任何像素,则重复所有步骤直到没有图像像素如此改变。
|
||||
<p>
|
||||
任务:
|
||||
编写一个例程,在1和0的图像矩阵上执行Zhang-Suen细化。
|
||||
</p>
|
||||
</pre></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>thinImage</code>必须是一个函数
|
||||
testString: assert.equal(typeof thinImage, 'function');
|
||||
- text: <code>thinImage</code>必须返回一个数组
|
||||
testString: assert(Array.isArray(result));
|
||||
- text: <code>thinImage</code>必须返回一个字符串数组
|
||||
testString: assert.equal(typeof result[0], 'string');
|
||||
- text: <code>thinImage</code>必须返回一个字符串数组
|
||||
testString: assert.deepEqual(result, expected);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
const testImage = [
|
||||
' ',
|
||||
' ################# ############# ',
|
||||
' ################## ################ ',
|
||||
' ################### ################## ',
|
||||
' ######## ####### ################### ',
|
||||
' ###### ####### ####### ###### ',
|
||||
' ###### ####### ####### ',
|
||||
' ################# ####### ',
|
||||
' ################ ####### ',
|
||||
' ################# ####### ',
|
||||
' ###### ####### ####### ',
|
||||
' ###### ####### ####### ',
|
||||
' ###### ####### ####### ###### ',
|
||||
' ######## ####### ################### ',
|
||||
' ######## ####### ###### ################## ###### ',
|
||||
' ######## ####### ###### ################ ###### ',
|
||||
' ######## ####### ###### ############# ###### ',
|
||||
' '];
|
||||
|
||||
function thinImage(image) {
|
||||
// Good luck!
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,76 @@
|
||||
---
|
||||
title: Zig-zag matrix
|
||||
id: 594810f028c0303b75339ad8
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
localeTitle: 之字形矩阵
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> “zig-zag”数组是第一个$ N ^ 2 $整数的正方形排列,当数组沿着数组的<a href="https://en.wiktionary.org/wiki/antidiagonal">反对角线</a>曲折时,数字会逐渐增加。例如,给定“'5”',产生这个数组: <pre> 0 1 5 6 14
|
||||
2 4 7 13 15
|
||||
3 8 12 16 21
|
||||
9 11 17 20 22
|
||||
10 18 19 23 24
|
||||
</pre>编写一个采用Z字形矩阵大小的函数,并将相应的矩阵作为二维数组返回。 </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: ZigZagMatrix必须是一个功能
|
||||
testString: assert.equal(typeof ZigZagMatrix, 'function');
|
||||
- text: ZigZagMatrix应该返回数组
|
||||
testString: assert.equal(typeof ZigZagMatrix(1), 'object');
|
||||
- text: ZigZagMatrix应该返回一个nestes数组的数组
|
||||
testString: assert.equal(typeof ZigZagMatrix(1)[0], 'object');
|
||||
- text: 'ZigZagMatrix(1)应返回[[0]]'
|
||||
testString: assert.deepEqual(ZigZagMatrix(1), zm1);
|
||||
- text: 'ZigZagMatrix(2)应返回[[0,1],[2,3]]'
|
||||
testString: assert.deepEqual(ZigZagMatrix(2), zm2);
|
||||
- text: ZigZagMatrix(5)必须返回指定的矩阵
|
||||
testString: assert.deepEqual(ZigZagMatrix(5), zm5);
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function ZigZagMatrix(n) {
|
||||
// Good luck!
|
||||
return [[], []];
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
Reference in New Issue
Block a user