fix(challenges): T problems
This commit is contained in:
@ -6,29 +6,29 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='description'>
|
<section id='description'>
|
||||||
A <a href="https://en.wikipedia.org/wiki/Hardy–Ramanujan number" title="wp: Hardy–Ramanujan number">taxicab number</a>
|
A <a href="https://en.wikipedia.org/wiki/Hardy–Ramanujan number" title="wp: Hardy–Ramanujan number" target="_blank">taxicab number</a> (the definition that is being used here) is a positive integer that can be expressed as the sum of two positive cubes in more than one way.
|
||||||
(the definition that is being used here) is a positive integer that can be expressed as the sum of two positive cubes in more than one way.
|
The first taxicab number is <b>1729</b>, which is:
|
||||||
The first taxicab number is 1729, which is:
|
<span style="margin-left: 2em;">1<sup>3</sup> + 12<sup>3</sup> and</span>
|
||||||
1<sup>3</sup> + 12<sup>3</sup> and
|
<span style="margin-left: 2em;">9<sup>3</sup> + 10<sup>3</sup>.</span>
|
||||||
9<sup>3</sup> + 10<sup>3</sup>.
|
|
||||||
Taxicab numbers are also known as:
|
Taxicab numbers are also known as:
|
||||||
* taxi numbers
|
<ul>
|
||||||
* taxi-cab numbers
|
<li>taxi numbers</li>
|
||||||
* taxi cab numbers
|
<li>taxi-cab numbers</li>
|
||||||
* Hardy-Ramanujan numbers
|
<li>taxi cab numbers</li>
|
||||||
Task:
|
<li>Hardy-Ramanujan numbers</li>
|
||||||
Write a function that returns the lowest N taxicab numbers.
|
</ul>
|
||||||
For each of the taxicab numbers, show the number as well as it's constituent cubes.
|
|
||||||
See also:
|
|
||||||
[http://oeis.org/A001235 A001235 taxicab numbers] on The On-Line Encyclopedia of Integer Sequences.
|
|
||||||
<a href="http://mathworld.wolfram.com/Hardy-RamanujanNumber.html">Hardy-Ramanujan Number</a> on MathWorld.
|
|
||||||
<a href="http://mathworld.wolfram.com/TaxicabNumber.html">taxicab number</a> on MathWorld.
|
|
||||||
<a href="https://en.wikipedia.org/wiki/Taxicab_number">taxicab number</a> on Wikipedia.
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
<section id='instructions'>
|
<section id='instructions'>
|
||||||
|
Write a function that returns the lowest <code>n</code> taxicab numbers. For each of the taxicab numbers, show the number as well as its constituent cubes.
|
||||||
|
<b>See also:</b>
|
||||||
|
<ul>
|
||||||
|
<li><a href="http://oeis.org/A001235" target="_blank">A001235 taxicab numbers</a> on The On-Line Encyclopedia of Integer Sequences.</li>
|
||||||
|
<li><a href="http://mathworld.wolfram.com/Hardy-RamanujanNumber.html" target="_blank">Hardy-Ramanujan Number</a> on MathWorld.</li>
|
||||||
|
<li><a href="http://mathworld.wolfram.com/TaxicabNumber.html" target="_blank">taxicab number</a> on MathWorld.</li>
|
||||||
|
<li><a href="https://en.wikipedia.org/wiki/Taxicab_number" target="_blank">taxicab number</a> on Wikipedia.</li>
|
||||||
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
@ -36,18 +36,18 @@ See also:
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
tests:
|
tests:
|
||||||
- text: <code>taxicabNumbers </code> is a function.
|
- text: <code>taxicabNumbers</code> is a function.
|
||||||
testString: assert(typeof taxicabNumbers === 'function', '<code>taxicabNumbers </code> is a function.');
|
testString: assert(typeof taxicabNumbers === 'function', '<code>taxicabNumbers</code> is a function.');
|
||||||
- text: <code>taxicabNumbers </code> should return an array.
|
- text: <code>taxicabNumbers</code> should return an array.
|
||||||
testString: assert(typeof taxicabNumbers(2) === 'object', '<code>taxicabNumbers </code> should return an array.');
|
testString: assert(typeof taxicabNumbers(2) === 'object', '<code>taxicabNumbers</code> should return an array.');
|
||||||
- text: <code>taxicabNumbers </code> should return an array of numbers.
|
- text: <code>taxicabNumbers</code> should return an array of numbers.
|
||||||
testString: assert(typeof taxicabNumbers(100)[0] === 'number', '<code>taxicabNumbers </code> should return an array of numbers.');
|
testString: assert(typeof taxicabNumbers(100)[0] === 'number', '<code>taxicabNumbers</code> should return an array of numbers.');
|
||||||
- text: <code>taxicabNumbers(4) </code> must return [1729, 4104, 13832, 20683].
|
- text: <code>taxicabNumbers(4)</code> must return [1729, 4104, 13832, 20683].
|
||||||
testString: assert.deepEqual(taxicabNumbers(4), res4, '<code>taxicabNumbers(4) </code> must return [1729, 4104, 13832, 20683].');
|
testString: assert.deepEqual(taxicabNumbers(4), res4, '<code>taxicabNumbers(4)</code> must return [1729, 4104, 13832, 20683].');
|
||||||
- text: taxicabNumbers(25) should return [1729, 4104, 13832, 20683, 32832, 39312, 40033, 46683, 64232, 65728, 110656, 110808, 134379, 149389, 165464, 171288, 195841, 216027, 216125, 262656, 314496, 320264, 327763, 373464, 402597]
|
- text: <code>taxicabNumbers(25)</code> should return [1729, 4104, 13832, 20683, 32832, 39312, 40033, 46683, 64232, 65728, 110656, 110808, 134379, 149389, 165464, 171288, 195841, 216027, 216125, 262656, 314496, 320264, 327763, 373464, 402597]
|
||||||
testString: assert.deepEqual(taxicabNumbers(25), res25, 'taxicabNumbers(25) should return [1729, 4104, 13832, 20683, 32832, 39312, 40033, 46683, 64232, 65728, 110656, 110808, 134379, 149389, 165464, 171288, 195841, 216027, 216125, 262656, 314496, 320264, 327763, 373464, 402597]');
|
testString: assert.deepEqual(taxicabNumbers(25), res25, '<code>taxicabNumbers(25)</code> should return [1729, 4104, 13832, 20683, 32832, 39312, 40033, 46683, 64232, 65728, 110656, 110808, 134379, 149389, 165464, 171288, 195841, 216027, 216125, 262656, 314496, 320264, 327763, 373464, 402597]');
|
||||||
- text: taxicabNumbers(39) resulting numbers from 20 - 29 should be [314496,320264,327763,373464,402597,439101,443889,513000,513856].
|
- text: <code>taxicabNumbers(39)</code> resulting numbers from 20 - 29 should be [314496,320264,327763,373464,402597,439101,443889,513000,513856].
|
||||||
testString: assert.deepEqual(taxicabNumbers(39).slice(20, 29), res39From20To29, 'taxicabNumbers(39) resulting numbers from 20 - 29 should be [314496,320264,327763,373464,402597,439101,443889,513000,513856].');
|
testString: assert.deepEqual(taxicabNumbers(39).slice(20, 29), res39From20To29, '<code>taxicabNumbers(39)</code> resulting numbers from 20 - 29 should be [314496,320264,327763,373464,402597,439101,443889,513000,513856].');
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ tests:
|
|||||||
<div id='js-seed'>
|
<div id='js-seed'>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function taxicabNumbers (n) {
|
function taxicabNumbers(n) {
|
||||||
// Good luck!
|
// Good luck!
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -6,31 +6,32 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='description'>
|
<section id='description'>
|
||||||
<p>
|
|
||||||
Write a function or program that can split a string at each non-escaped occurrence of a separator character.
|
Write a function or program that can split a string at each non-escaped occurrence of a separator character.
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
It should accept three input parameters:
|
It should accept three input parameters:
|
||||||
</p>
|
<ul>
|
||||||
The <b>string</b>
|
<li>The <b>string</b></li>
|
||||||
The <b>separator character</b>
|
<li>The <b>separator character</b></li>
|
||||||
The <b>escape character</b>
|
<li>The <b>escape character</b></li>
|
||||||
<p>It should output a list of strings.</p>
|
</ul>
|
||||||
<p>Rules for splitting:</p>
|
It should output a list of strings.
|
||||||
The fields that were separated by the separators, become the elements of the output list.
|
Rules for splitting:
|
||||||
Empty fields should be preserved, even at the start and end.
|
<ul>
|
||||||
<p>Rules for escaping:</p>
|
<li>The fields that were separated by the separators, become the elements of the output list.</li>
|
||||||
"Escaped" means preceded by an occurrence of the escape character that is not already escaped itself.
|
<li>Empty fields should be preserved, even at the start and end.</li>
|
||||||
When the escape character precedes a character that has no special meaning, it still counts as an escape (but does not do anything special).
|
</ul>
|
||||||
Each occurrences of the escape character that was used to escape something, should not become part of the output.
|
Rules for escaping:
|
||||||
<p>Demonstrate that your function satisfies the following test-case:
|
<ul>
|
||||||
Given string <pre>one^|uno||three^^^^|four^^^|^cuatro|</pre> and using
|
<li>"Escaped" means preceded by an occurrence of the escape character that is not already escaped itself.</li>
|
||||||
<pre>|</pre> as a separator and <pre>^</pre> as escape character, your
|
<li>When the escape character precedes a character that has no special meaning, it still counts as an escape (but does not do anything special).</li>
|
||||||
function should output the following array:
|
<li>Each occurrences of the escape character that was used to escape something, should not become part of the output.</li>
|
||||||
</p>
|
</ul>
|
||||||
<pre>
|
Demonstrate that your function satisfies the following test-case:
|
||||||
['one|uno', '', 'three^^', 'four^|quatro', '']
|
Given the string
|
||||||
</pre>
|
<pre>one^|uno||three^^^^|four^^^|^cuatro|</pre>
|
||||||
|
and using <code>|</code> as a separator and <code>^</code> as escape character, your function should output the following array:
|
||||||
|
<pre>
|
||||||
|
['one|uno', '', 'three^^', 'four^|cuatro', '']
|
||||||
|
</pre>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
|
@ -6,8 +6,7 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='description'>
|
<section id='description'>
|
||||||
Task:
|
Find the top <code>n</code> ranked data in each group, where <code>n</code> is provided as a parameter. Name of the rank and the group are also provided as parameter.
|
||||||
<p>Find the top N ranked data in each group, where N is provided as a parameter. Name of the rank and the group are also provided as parameter.</p>
|
|
||||||
Given the following data:
|
Given the following data:
|
||||||
<pre>
|
<pre>
|
||||||
[
|
[
|
||||||
@ -119,7 +118,6 @@ const testData2 = [
|
|||||||
const res2 = topRankPerGroup(1, testData2, 'genre', 'rating');
|
const res2 = topRankPerGroup(1, testData2, 'genre', 'rating');
|
||||||
const res3 = topRankPerGroup(2, testData2, 'genre', 'rating');
|
const res3 = topRankPerGroup(2, testData2, 'genre', 'rating');
|
||||||
|
|
||||||
//console.log(JSON.stringify(topRankPerGroup(10, testData1)));
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -6,25 +6,20 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='description'>
|
<section id='description'>
|
||||||
<p>
|
Given a mapping between items, and items they depend on, a <a href="https://en.wikipedia.org/wiki/Topological sorting" title="wp: Topological sorting" target="_blank">topological sort</a> orders items so that no item precedes an item it depends upon.
|
||||||
Given a mapping between items, and items they depend on, a
|
The compiling of a library in the <a href="https://en.wikipedia.org/wiki/VHDL" title="wp: VHDL" target="_blank">VHDL</a> language has the constraint that a library must be compiled after any library it depends on.
|
||||||
<a href="https://en.wikipedia.org/wiki/Topological sorting" title="wp: Topological sorting">topological sort</a> orders
|
</section>
|
||||||
items so that no item precedes an item it depends upon.
|
|
||||||
</p>
|
## Instructions
|
||||||
<p>
|
<section id='instructions'>
|
||||||
The compiling of a library in the
|
|
||||||
<a href="https://en.wikipedia.org/wiki/VHDL" title="wp: VHDL">VHDL</a> language
|
|
||||||
has the constraint that a library must be compiled after any library it depends on.
|
|
||||||
</p>
|
|
||||||
Task:
|
|
||||||
<p>
|
|
||||||
Write a function that will return a valid compile order of VHDL libraries from their dependencies.
|
Write a function that will return a valid compile order of VHDL libraries from their dependencies.
|
||||||
</p>
|
<ul>
|
||||||
Assume library names are single words.
|
<li>Assume library names are single words.</li>
|
||||||
Items mentioned as only dependents have no dependents of their own, but their order of compiling must be given.
|
<li>Items mentioned as only dependents have no dependents of their own, but their order of compiling must be given.</li>
|
||||||
Any self dependencies should be ignored.
|
<li>Any self dependencies should be ignored.</li>
|
||||||
Any un-orderable dependencies should be ignored.
|
<li>Any un-orderable dependencies should be ignored.</li>
|
||||||
<p>Use the following data as an example:</p>
|
</ul>
|
||||||
|
Use the following data as an example:
|
||||||
<pre>
|
<pre>
|
||||||
LIBRARY LIBRARY DEPENDENCIES
|
LIBRARY LIBRARY DEPENDENCIES
|
||||||
======= ====================
|
======= ====================
|
||||||
@ -42,29 +37,16 @@ ramlib std ieee
|
|||||||
std_cell_lib ieee std_cell_lib
|
std_cell_lib ieee std_cell_lib
|
||||||
synopsys
|
synopsys
|
||||||
</pre>
|
</pre>
|
||||||
<p>
|
|
||||||
<small>Note: the above data would be un-orderable if, for example, <code>dw04</code> is added to the list of dependencies of <code>dw01</code>.</small>
|
<small>Note: the above data would be un-orderable if, for example, <code>dw04</code> is added to the list of dependencies of <code>dw01</code>.</small>
|
||||||
</p>
|
<b>C.f.:</b>
|
||||||
C.f.:
|
<ul>
|
||||||
|
<li><a href="http://rosettacode.org/wiki/Topological sort/Extracted top item" title="Topological sort/Extracted top item" target="_blank">Topological sort/Extracted top item</a>.</li>
|
||||||
<a href="http://rosettacode.org/wiki/Topological sort/Extracted top item" title="Topological sort/Extracted top item">Topological sort/Extracted top item</a>.
|
</ul>
|
||||||
|
There are two popular algorithms for topological sorting:
|
||||||
<p>There are two popular algorithms for topological sorting:</p>
|
<ul>
|
||||||
<p>
|
<li><a href="https://en.wikipedia.org/wiki/Topological sorting" title="wp: Topological sorting" target="_blank">Kahn's 1962 topological sort</a></li>
|
||||||
Kahn's 1962 topological sort, and depth-first search:
|
<li><a href="http://www.embeddedrelated.com/showarticle/799.php" title="link: http://www.embeddedrelated.com/showarticle/799.php" target="_blank">depth-first search</a></li>
|
||||||
<a href="https://en.wikipedia.org/wiki/Topological sorting" title="wp: Topological sorting">topological sort</a>
|
</ul>
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Jason Sachs:
|
|
||||||
<a href="http://www.embeddedrelated.com/showarticle/799.php" title="link: http://www.embeddedrelated.com/showarticle/799.php">
|
|
||||||
"Ten little algorithms, part 4: topological sort"
|
|
||||||
</a>.
|
|
||||||
</p>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Instructions
|
|
||||||
<section id='instructions'>
|
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
@ -6,16 +6,9 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='description'>
|
<section id='description'>
|
||||||
Task:
|
Solve the <a href="https://en.wikipedia.org/wiki/Towers_of_Hanoi" title="wp: Towers_of_Hanoi" target="_blank">Towers of Hanoi</a> problem.</p>
|
||||||
<p>Solve the <a href="https://en.wikipedia.org/wiki/Towers_of_Hanoi" title="wp: Towers_of_Hanoi">Towers of Hanoi</a> problem.</p>
|
Your solution should accept the number of discs as the first parameters, and three string used to identify each of the three stacks of discs, for example <code>towerOfHanoi(4, 'A', 'B', 'C')</code>. The function should return an array of arrays containing the list of moves, source -> destination.
|
||||||
<p>
|
For example, the array <code>[['A', 'C'], ['B', 'A']]</code> indicates that the 1st move was to move a disc from stack A to C, and the 2nd move was to move a disc from stack B to A.
|
||||||
Your solution should accept the number of discs as the first parameters, and
|
|
||||||
three string used to identify each of the three stacks of discs, for example
|
|
||||||
<code>towerOfHanoi(4, 'A', 'B', 'C')</code>. The function should return an
|
|
||||||
array of arrays containing the list of moves, source -> destination. For
|
|
||||||
example, the array <code>[['A', 'C'], ['B', 'A']]</code> indicates that the
|
|
||||||
1st move was to move a disc from stack A to C, and the 2nd move was to move a
|
|
||||||
disc from stack B to A.
|
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@ -50,7 +43,7 @@ tests:
|
|||||||
<div id='js-seed'>
|
<div id='js-seed'>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function towerOfHanoi (n, a, b, c) {
|
function towerOfHanoi(n, a, b, c) {
|
||||||
// Good luck!
|
// Good luck!
|
||||||
return [[]];
|
return [[]];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user