fix(challenges): G problems

This commit is contained in:
Kris Koishigawa
2019-03-05 14:39:16 +09:00
committed by mrugesh
parent abbfee1189
commit 537d1ed642
7 changed files with 51 additions and 39 deletions

View File

@ -46,7 +46,7 @@ tests:
<div id='js-seed'>
```js
function gamma (x) {
function gamma(x) {
// Good luck!
}
```

View File

@ -6,7 +6,9 @@ challengeType: 5
## Description
<section id='description'>
Write a function to solve \(A.x = b\) using Gaussian elimination then backwards substitution. \(A\) being an \(n \times n\) matrix. Also, \(x\) and \(b\) are \(n\) by 1 vectors. To improve accuracy, please use partial pivoting and scaling.
Write a function to solve \(Ax = b\) using Gaussian elimination then backwards substitution.
\(A\) being an \(n \times n\) matrix. Also, \(x\) and \(b\) are \(n\) by 1 vectors.
To improve accuracy, please use partial pivoting and scaling.
</section>
## Instructions
@ -44,7 +46,7 @@ tests:
<div id='js-seed'>
```js
function gaussianElimination (A,b) {
function gaussianElimination(A,b) {
// Good luck!
}
```

View File

@ -8,7 +8,7 @@ challengeType: 5
<section id='description'>
Write a generalized version of <a href="http://rosettacode.org/wiki/FizzBuzz">FizzBuzz</a> that works for any list of factors, along with their words.
This is basically a "fizzbuzz" implementation where the rules of the game are supplied to the user. Create a function to implement this. The function should take two parameters.
The first will be an array with the FizzBuzz rules. For example: <code>[ [3,"Fizz"] , [5,"Buzz"] ]</code>.
The first will be an array with the FizzBuzz rules. For example: <code>[ [3, "Fizz"] , [5, "Buzz"] ]</code>.
This indcates that <code>Fizz</code> should be printed if the number is a multiple of 3 and <code>Buzz</code> if it is a multiple of 5. If it is a multiple of both then the strings should be concatenated in the order specified in the array. In this case, <code>FizzBuzz</code> if the number is a multiple of 3 and 5.
The second parameter is the number for which the function should return a string as stated above.
</section>
@ -52,7 +52,7 @@ tests:
<div id='js-seed'>
```js
function genFizzBuzz (rules, num) {
function genFizzBuzz(rules, num) {
// Good luck!
}
```

View File

@ -6,7 +6,7 @@ challengeType: 5
## Description
<section id='description'>
Write a function to generate an array of lower case ASCII characters, for a given range. For example: for range 1 to 4 the function should return <code>['a','b','c','d']</code>.
Write a function to generate an array of lower case ASCII characters for a given range. For example, given the range <code>['a', 'd']</code>, the function should return <code>['a', 'b', 'c', 'd']</code>.
</section>
## Instructions
@ -44,7 +44,7 @@ tests:
<div id='js-seed'>
```js
function lascii (cFrom, cTo) {
function lascii(cFrom, cTo) {
// Good luck!
}
```

View File

@ -9,14 +9,13 @@ challengeType: 5
A generator is an executable entity (like a function or procedure) that contains code that yields a sequence of values, one at a time, so that each time you call the generator, the next value in the sequence is provided.
Generators are often built on top of coroutines or objects so that the internal state of the object is handled “naturally”.
Generators are often used in situations where a sequence is potentially infinite, and where it is possible to construct the next value of the sequence with only minimal state.
Write a function that uses generators to generate squares and cubes. Create a new generator that filters all cubes from the generator of squares.
The function should return the \( n^{th} \) value of the filtered generator.
For example for \(n=7\), the function should return 81 as the sequence would be 4,9,16,25,36,49,81. Here 64 is filtered out, as it is a cube.
</section>
## Instructions
<section id='instructions'>
Write a function that uses generators to generate squares and cubes. Create a new generator that filters all cubes from the generator of squares.
The function should return the \( n^{th} \) value of the filtered generator.
For example for \(n=7\), the function should return 81 as the sequence would be 4, 9, 16, 25, 36, 49, 81. Here 64 is filtered out, as it is a cube.
</section>
## Tests
@ -49,7 +48,7 @@ tests:
<div id='js-seed'>
```js
function exponentialGenerator (n) {
function exponentialGenerator(n) {
// Good luck!
}
```

View File

@ -6,21 +6,34 @@ challengeType: 5
## Description
<section id='description'>
<a href="https://en.wikipedia.org/wiki/Gray code">Gray code</a> is a form of binary encoding where transitions between consecutive numbers differ by only one bit.
<a href="https://en.wikipedia.org/wiki/Gray code" target="_blank">Gray code</a> is a form of binary encoding where transitions between consecutive numbers differ by only one bit.
This is a useful encoding for reducing hardware data hazards with values that change rapidly and/or connect to slower hardware as inputs.
It is also useful for generating inputs for <a href="https://en.wikipedia.org/wiki/Karnaugh map">Karnaugh maps</a> in order from left to right or top to bottom.
Create a function to encode a number to and decode a number from Gray code. The function should will have 2 parameters.
The first would be a boolean. The function should encode for true and decode for false. The second parameter would be the number to be encoded/decoded.
Display the normal binary representations, Gray code representations, and decoded Gray code values for all 5-bit binary numbers (0-31 inclusive, leading 0's not necessary).
There are many possible Gray codes. The following encodes what is called "binary reflected Gray code."<br>Encoding (MSB is bit 0, b is binary, g is Gray code):
<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> Or: <br><code> g = b xor (b logically right shifted 1 time)</code><br>Decoding (MSB is bit 0, b is binary, g is Gray code): <br>
<code>b[0] = g[0]<br>for other bits:<br>b[i] = g[i] xor b[i-1]<br></code>
It is also useful for generating inputs for <a href="https://en.wikipedia.org/wiki/Karnaugh map" target="_blank">Karnaugh maps</a> in order from left to right or top to bottom.
</section>
## Instructions
<section id='instructions'>
Create a function to encode a number to and decode a number from Gray code. The function should will have 2 parameters.
The first would be a boolean. The function should encode for true and decode for false. The second parameter would be the number to be encoded/decoded.
Display the normal binary representations, Gray code representations, and decoded Gray code values for all 5-bit binary numbers (0-31 inclusive, leading 0's not necessary).
There are many possible Gray codes. The following encodes what is called "binary reflected Gray code."
Encoding (MSB is bit 0, b is binary, g is Gray code):
<pre>
if b[i-1] = 1
g[i] = not b[i]
else
g[i] = b[i]
</pre>
Or:
<pre>
g = b xor (b logically right shifted 1 time)
</pre>
Decoding (MSB is bit 0, b is binary, g is Gray code):
<pre>
b[0] = g[0]<br>
for other bits:
b[i] = g[i] xor b[i-1]
</pre>
</section>
## Tests

View File

@ -22,20 +22,20 @@ An empty subsequence is considered to have the sum of \( 0 \); thus if all elem
tests:
- text: <code>maximumSubsequence</code> should be a function.
testString: assert(typeof maximumSubsequence=='function','<code>maximumSubsequence</code> should be a function.');
- text: <code>maximumSubsequence([1,2,-1,3,10,-10])</code> should return an array.
testString: assert(Array.isArray(maximumSubsequence([1,2,-1,3,10,-10])),'<code>maximumSubsequence([1,2,-1,3,10,-10])</code> should return an array.');
- text: <code>maximumSubsequence([1,2,-1,3,10,-10])</code> should return <code>[ 1, 2, -1, 3, 10 ]</code>.
testString: assert.deepEqual(maximumSubsequence([1,2,-1,3,10,-10]), [ 1, 2, -1, 3, 10 ],'<code>maximumSubsequence([1,2,-1,3,10,-10])</code> should return <code>[ 1, 2, -1, 3, 10 ]</code>.');
- text: <code>maximumSubsequence([0, 8, 10, -2, -4, -1, -5, -3])</code> should return <code>[ 0, 8, 10 ]</code>.
testString: assert.deepEqual(maximumSubsequence([0, 8, 10, -2, -4, -1, -5, -3]), [ 0, 8, 10 ],'<code>maximumSubsequence([0, 8, 10, -2, -4, -1, -5, -3])</code> should return <code>[ 0, 8, 10 ]</code>.');
- text: <code>maximumSubsequence([9, 9, -10, 1])</code> should return <code>[ 9, 9 ]</code>.
testString: assert.deepEqual(maximumSubsequence([9, 9, -10, 1]), [ 9, 9 ],'<code>maximumSubsequence([9, 9, -10, 1])</code> should return <code>[ 9, 9 ]</code>.');
- text: <code>maximumSubsequence([7, 1, -5, -3, -8, 1]</code> should return <code>[ 7, 1 ]</code>.
testString: assert.deepEqual(maximumSubsequence([7, 1, -5, -3, -8, 1]), [ 7, 1 ],'<code>maximumSubsequence([7, 1, -5, -3, -8, 1]</code> should return <code>[ 7, 1 ]</code>.');
- text: <code>maximumSubsequence([-3, 6, -1, 4, -4, -6])</code> should return <code>[ 6, -1, 4 ]</code>.
testString: assert.deepEqual(maximumSubsequence([-3, 6, -1, 4, -4, -6]), [ 6, -1, 4 ],'<code>maximumSubsequence([-3, 6, -1, 4, -4, -6])</code> should return <code>[ 6, -1, 4 ]</code>.');
- text: <code>maximumSubsequence([-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1])</code> should return <code>[ 3, 5, 6, -2, -1, 4 ]</code>.
testString: assert.deepEqual(maximumSubsequence([-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1]), [ 3, 5, 6, -2, -1, 4 ],'<code>maximumSubsequence([-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1])</code> should return <code>[ 3, 5, 6, -2, -1, 4 ]</code>.');
- text: <code>maximumSubsequence([ 1, 2, -1, 3, 10, -10 ])</code> should return an array.
testString: assert(Array.isArray(maximumSubsequence([ 1, 2,-1, 3, 10, -10 ])),'<code>maximumSubsequence([ 1, 2, -1, 3, 10, -10 ])</code> should return an array.');
- text: <code>maximumSubsequence([ 1, 2, -1, 3, 10, -10 ])</code> should return <code>[ 1, 2, -1, 3, 10 ]</code>.
testString: assert.deepEqual(maximumSubsequence([1,2,-1,3,10,-10]), [ 1, 2, -1, 3, 10 ],'<code>maximumSubsequence([ 1, 2, -1, 3, 10, -10 ])</code> should return <code>[ 1, 2, -1, 3, 10 ]</code>.');
- text: <code>maximumSubsequence([ 0, 8, 10, -2, -4, -1, -5, -3 ])</code> should return <code>[ 0, 8, 10 ]</code>.
testString: assert.deepEqual(maximumSubsequence([0, 8, 10, -2, -4, -1, -5, -3]), [ 0, 8, 10 ],'<code>maximumSubsequence([ 0, 8, 10, -2, -4, -1, -5, -3 ])</code> should return <code>[ 0, 8, 10 ]</code>.');
- text: <code>maximumSubsequence([ 9, 9, -10, 1 ])</code> should return <code>[ 9, 9 ]</code>.
testString: assert.deepEqual(maximumSubsequence([ 9, 9, -10, 1 ]), [ 9, 9 ],'<code>maximumSubsequence([ 9, 9, -10, 1 ])</code> should return <code>[ 9, 9 ]</code>.');
- text: <code>maximumSubsequence([ 7, 1, -5, -3, -8, 1 ]</code> should return <code>[ 7, 1 ]</code>.
testString: assert.deepEqual(maximumSubsequence([ 7, 1, -5, -3, -8, 1 ]), [ 7, 1 ],'<code>maximumSubsequence([ 7, 1, -5, -3, -8, 1 ]</code> should return <code>[ 7, 1 ]</code>.');
- text: <code>maximumSubsequence([ -3, 6, -1, 4, -4, -6 ])</code> should return <code>[ 6, -1, 4 ]</code>.
testString: assert.deepEqual(maximumSubsequence([ -3, 6, -1, 4, -4, -6 ]), [ 6, -1, 4 ],'<code>maximumSubsequence([ -3, 6, -1, 4, -4, -6 ])</code> should return <code>[ 6, -1, 4 ]</code>.');
- text: <code>maximumSubsequence([ -1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1 ])</code> should return <code>[ 3, 5, 6, -2, -1, 4 ]</code>.
testString: assert.deepEqual(maximumSubsequence([ -1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1 ]), [ 3, 5, 6, -2, -1, 4 ],'<code>maximumSubsequence([ -1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1 ])</code> should return <code>[ 3, 5, 6, -2, -1, 4 ]</code>.');
```
@ -47,7 +47,7 @@ tests:
<div id='js-seed'>
```js
function maximumSubsequence (population) {
function maximumSubsequence(population) {
// Good luck!
}
```
@ -87,8 +87,6 @@ function maximumSubsequence(population) {
return greatest;
}
```
</section>