fix(challenges): T problems

This commit is contained in:
Kris Koishigawa
2019-03-10 22:12:52 +09:00
committed by mrugesh
parent 539e93d01b
commit 74f70c19d8
5 changed files with 82 additions and 108 deletions

View File

@ -6,29 +6,29 @@ challengeType: 5
## Description
<section id='description'>
A &nbsp; <a href="https://en.wikipedia.org/wiki/HardyRamanujan number" title="wp: HardyRamanujan number">taxicab number</a>
&nbsp; (the definition that is being used here) &nbsp; 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 &nbsp; 1729, &nbsp; which is:
1<sup>3</sup> &nbsp; + &nbsp; 12<sup>3</sup> &nbsp; &nbsp; &nbsp; and
9<sup>3</sup> &nbsp; + &nbsp; 10<sup>3</sup>.
A &nbsp; <a href="https://en.wikipedia.org/wiki/HardyRamanujan number" title="wp: HardyRamanujan 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 first taxicab number is <b>1729</b>, which is:
<span style="margin-left: 2em;">1<sup>3</sup> &nbsp; + &nbsp; 12<sup>3</sup> &nbsp; &nbsp; &nbsp; and</span>
<span style="margin-left: 2em;">9<sup>3</sup> &nbsp; + &nbsp; 10<sup>3</sup>.</span>
Taxicab numbers are also known as:
* &nbsp; taxi numbers
* &nbsp; taxi-cab numbers
* &nbsp; taxi cab numbers
* &nbsp; Hardy-Ramanujan numbers
Task:
Write a function that returns the lowest N taxicab numbers.
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.
<ul>
<li>taxi numbers</li>
<li>taxi-cab numbers</li>
<li>taxi cab numbers</li>
<li>Hardy-Ramanujan numbers</li>
</ul>
</section>
## 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>
## Tests
@ -36,18 +36,18 @@ See also:
```yml
tests:
- text: <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.
testString: assert(typeof taxicabNumbers(2) === 'object', '<code>taxicabNumbers </code> should return an array.');
- 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.');
- 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].');
- 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]
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]');
- text: 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, 'taxicabNumbers(39) resulting numbers from 20 - 29 should be [314496,320264,327763,373464,402597,439101,443889,513000,513856].');
- text: <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.
testString: assert(typeof taxicabNumbers(2) === 'object', '<code>taxicabNumbers</code> should return an array.');
- 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.');
- 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].');
- 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, '<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: <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, '<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'>
```js
function taxicabNumbers (n) {
function taxicabNumbers(n) {
// Good luck!
return true;
}

View File

@ -6,31 +6,32 @@ challengeType: 5
## Description
<section id='description'>
<p>
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:
</p>
The <b>string</b>
The <b>separator character</b>
The <b>escape character</b>
<p>It should output a list of strings.</p>
<p>Rules for splitting:</p>
The fields that were separated by the separators, become the elements of the output list.
Empty fields should be preserved, even at the start and end.
<p>Rules for escaping:</p>
"Escaped" means preceded by an occurrence of the escape character that is not already escaped itself.
When the escape character precedes a character that has no special meaning, it still counts as an escape (but does not do anything special).
Each occurrences of the escape character that was used to escape something, should not become part of the output.
<p>Demonstrate that your function satisfies the following test-case:
Given string <pre>one^|uno||three^^^^|four^^^|^cuatro|</pre> and using
<pre>|</pre> as a separator and <pre>^</pre> as escape character, your
function should output the following array:
</p>
<pre>
['one|uno', '', 'three^^', 'four^|quatro', '']
</pre>
<ul>
<li>The <b>string</b></li>
<li>The <b>separator character</b></li>
<li>The <b>escape character</b></li>
</ul>
It should output a list of strings.
Rules for splitting:
<ul>
<li>The fields that were separated by the separators, become the elements of the output list.</li>
<li>Empty fields should be preserved, even at the start and end.</li>
</ul>
Rules for escaping:
<ul>
<li>"Escaped" means preceded by an occurrence of the escape character that is not already escaped itself.</li>
<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>
<li>Each occurrences of the escape character that was used to escape something, should not become part of the output.</li>
</ul>
Demonstrate that your function satisfies the following test-case:
Given the string
<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>
## Instructions

View File

@ -6,8 +6,7 @@ challengeType: 5
## Description
<section id='description'>
Task:
<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>
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.
Given the following data:
<pre>
[
@ -119,7 +118,6 @@ const testData2 = [
const res2 = topRankPerGroup(1, testData2, 'genre', 'rating');
const res3 = topRankPerGroup(2, testData2, 'genre', 'rating');
//console.log(JSON.stringify(topRankPerGroup(10, testData1)));
```
</div>

View File

@ -6,25 +6,20 @@ challengeType: 5
## 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">topological sort</a> orders
items so that no item precedes an item it depends upon.
</p>
<p>
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>
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.
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.
</section>
## Instructions
<section id='instructions'>
Write a function that will return a valid compile order of VHDL libraries from their dependencies.
</p>
Assume library names are single words.
Items mentioned as only dependents have no dependents of their own, but their order of compiling must be given.
Any self dependencies should be ignored.
Any un-orderable dependencies should be ignored.
<p>Use the following data as an example:</p>
<ul>
<li>Assume library names are single words.</li>
<li>Items mentioned as only dependents have no dependents of their own, but their order of compiling must be given.</li>
<li>Any self dependencies should be ignored.</li>
<li>Any un-orderable dependencies should be ignored.</li>
</ul>
Use the following data as an example:
<pre>
LIBRARY LIBRARY DEPENDENCIES
======= ====================
@ -42,29 +37,16 @@ ramlib std ieee
std_cell_lib ieee std_cell_lib
synopsys
</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>
</p>
C.f.:
<a href="http://rosettacode.org/wiki/Topological sort/Extracted top item" title="Topological sort/Extracted top item">Topological sort/Extracted top item</a>.
<p>There are two popular algorithms for topological sorting:</p>
<p>
Kahn's 1962 topological sort, and depth-first search:
<a href="https://en.wikipedia.org/wiki/Topological sorting" title="wp: Topological sorting">topological sort</a>
</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'>
<b>C.f.:</b>
<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>
</ul>
There are two popular algorithms for topological sorting:
<ul>
<li><a href="https://en.wikipedia.org/wiki/Topological sorting" title="wp: Topological sorting" target="_blank">Kahn's 1962 topological sort</a></li>
<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>
</ul>
</section>
## Tests

View File

@ -6,16 +6,9 @@ challengeType: 5
## Description
<section id='description'>
Task:
<p>Solve the <a href="https://en.wikipedia.org/wiki/Towers_of_Hanoi" title="wp: Towers_of_Hanoi">Towers of Hanoi</a> problem.</p>
<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. 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.
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>
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>
</section>
@ -50,7 +43,7 @@ tests:
<div id='js-seed'>
```js
function towerOfHanoi (n, a, b, c) {
function towerOfHanoi(n, a, b, c) {
// Good luck!
return [[]];
}