chore: manual translations (#42811)
This commit is contained in:
committed by
GitHub
parent
a3395269a0
commit
c4fd49e5b7
@ -24,10 +24,10 @@ Implement a function that takes a string of four digits as its argument, with ea
|
||||
<li> The order of the digits when given does not have to be preserved. </li>
|
||||
</ul>
|
||||
|
||||
| Example input | Example output |
|
||||
| ----------------------------- | ------------------------- |
|
||||
| <code>solve24("4878");</code> | <code>(7-8/8)\*4</code> |
|
||||
| <code>solve24("1234");</code> | <code>3\*1\*4\*2</code> |
|
||||
| Example input | Example output |
|
||||
| ------------------------- | ------------------------- |
|
||||
| <code>solve24("4878");</code> | <code>(7-8/8)\*4</code> |
|
||||
| <code>solve24("1234");</code> | <code>3\*1\*4\*2</code> |
|
||||
| <code>solve24("6789");</code> | <code>(6\*8)/(9-7)</code> |
|
||||
| <code>solve24("1127");</code> | <code>(1+7)\*(2+1)</code> |
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: 9-billion-names-of-god-the-integer
|
||||
|
||||
# --description--
|
||||
|
||||
This task is a variation of the [short story by Arthur C. Clarke](<https://en.wikipedia.org/wiki/The Nine Billion Names of God#Plot_summary> "wp: The Nine Billion Names of God#Plot_summary").
|
||||
This task is a variation of the [short story by Arthur C. Clarke](https://en.wikipedia.org/wiki/The Nine Billion Names of God#Plot_summary "wp: The Nine Billion Names of God#Plot_summary").
|
||||
|
||||
(Solvers should be aware of the consequences of completing this task.)
|
||||
|
||||
|
@ -8,35 +8,43 @@ dashedName: align-columns
|
||||
|
||||
# --description--
|
||||
|
||||
Given a text file of many lines, where fields within a line are delineated by a single `$` 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.
|
||||
Given an array of many lines, where fields within a line are delineated by a single `$` 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.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Use the following text to test your programs:
|
||||
|
||||
<pre>
|
||||
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.
|
||||
</pre>
|
||||
```js
|
||||
const testText = [
|
||||
'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.'
|
||||
];
|
||||
```
|
||||
|
||||
**Note that:**
|
||||
|
||||
<ul>
|
||||
<li>The example input texts lines may, or may not, have trailing dollar characters.</li>
|
||||
<li>All columns should share the same alignment.</li>
|
||||
<li>Consecutive space characters produced adjacent to the end of lines are insignificant for the purposes of the task.</li>
|
||||
<li>Output text will be viewed in a mono-spaced font on a plain text editor or basic terminal.</li>
|
||||
<li>The minimum space between columns should be computed from the text and not hard-coded.</li>
|
||||
<li>It is not a requirement to add separating characters between or around columns.</li>
|
||||
</ul>
|
||||
- The example input texts lines may, or may not, have trailing dollar characters.
|
||||
- All columns should share the same alignment.
|
||||
- Consecutive space characters produced adjacent to the end of lines are insignificant for the purposes of the task.
|
||||
- Output text will be viewed in a mono-spaced font on a plain text editor or basic terminal. Lines in it should be joined using new line character (`\n`).
|
||||
- The minimum space between columns should be computed from the text and not hard-coded.
|
||||
- It is not a requirement to add separating characters between or around columns.
|
||||
|
||||
For example, one of the lines from the `testText`, after jusitifing to the right, left and center respectivelly:
|
||||
|
||||
```js
|
||||
' column are separated by at least one space.\n'
|
||||
'column are separated by at least one space.\n'
|
||||
' column are separated by at least one space.\n'
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
@ -46,22 +54,22 @@ or$center$justified$within$its$column.
|
||||
assert(typeof formatText === 'function');
|
||||
```
|
||||
|
||||
`formatText` with the above input and "right" justification should produce the following:
|
||||
`formatText(testText, 'right')` should produce text with columns justified to the right.
|
||||
|
||||
```js
|
||||
assert.strictEqual(formatText(testInput, 'right'), rightAligned);
|
||||
assert.strictEqual(formatText(_testText, 'right'), rightAligned);
|
||||
```
|
||||
|
||||
`formatText` with the above input and "left" justification should produce the following:
|
||||
`formatText(testText, 'left')` should produce text with columns justified to the left.
|
||||
|
||||
```js
|
||||
assert.strictEqual(formatText(testInput, 'left'), leftAligned);
|
||||
assert.strictEqual(formatText(_testText, 'left'), leftAligned);
|
||||
```
|
||||
|
||||
`formatText` with the above input and "center" justification should produce the following:
|
||||
`formatText(testText, 'center')` should produce text with columns justified to the center.
|
||||
|
||||
```js
|
||||
assert.strictEqual(formatText(testInput, 'center'), centerAligned);
|
||||
assert.strictEqual(formatText(_testText, 'center'), centerAligned);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -69,10 +77,10 @@ assert.strictEqual(formatText(testInput, 'center'), centerAligned);
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
const testInput = [
|
||||
const _testText = [
|
||||
'Given$a$text$file$of$many$lines',
|
||||
'where$fields$within$a$line$',
|
||||
'are$delineated$by$a$single$\"dollar\"$character',
|
||||
'are$delineated$by$a$single$"dollar"$character',
|
||||
'write$a$program',
|
||||
'that$aligns$each$column$of$fields$',
|
||||
'by$ensuring$that$words$in$each$',
|
||||
@ -119,7 +127,11 @@ const centerAligned = ' Given a text file of many
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
const testArr = [
|
||||
function formatText(input, justification) {
|
||||
|
||||
}
|
||||
|
||||
const testText = [
|
||||
'Given$a$text$file$of$many$lines',
|
||||
'where$fields$within$a$line$',
|
||||
'are$delineated$by$a$single$"dollar"$character',
|
||||
@ -131,28 +143,11 @@ const testArr = [
|
||||
'justified,$right$justified',
|
||||
'or$center$justified$within$its$column.'
|
||||
];
|
||||
|
||||
function formatText(input, justification) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```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.'
|
||||
];
|
||||
|
||||
String.prototype.repeat = function (n) { return new Array(1 + parseInt(n)).join(this); };
|
||||
|
||||
function formatText(input, justification) {
|
||||
|
@ -8,7 +8,7 @@ dashedName: amicable-pairs
|
||||
|
||||
# --description--
|
||||
|
||||
Two integers $N$ and $M$ are said to be [amicable pairs](<https://en.wikipedia.org/wiki/Amicable numbers> "wp: Amicable numbers") if $N \\neq M$ and the sum of the [proper divisors](<https://rosettacode.org/wiki/Proper divisors> "Proper divisors") of $N$ ($\\mathrm{sum}(\\mathrm{propDivs}(N))$) $= M$ as well as $\\mathrm{sum}(\\mathrm{propDivs}(M)) = N$.
|
||||
Two integers $N$ and $M$ are said to be [amicable pairs](https://en.wikipedia.org/wiki/Amicable numbers "wp: Amicable numbers") if $N \\neq M$ and the sum of the [proper divisors](https://rosettacode.org/wiki/Proper divisors "Proper divisors") of $N$ ($\\mathrm{sum}(\\mathrm{propDivs}(N))$) $= M$ as well as $\\mathrm{sum}(\\mathrm{propDivs}(M)) = N$.
|
||||
|
||||
**Example:**
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: averagesmode
|
||||
|
||||
# --description--
|
||||
|
||||
Write a program to find the [mode](<https://en.wikipedia.org/wiki/Mode (statistics)> "wp: Mode (statistics)") value of a collection.
|
||||
Write a program to find the [mode](https://en.wikipedia.org/wiki/Mode (statistics) "wp: Mode (statistics)") value of a collection.
|
||||
|
||||
The case where the collection is empty may be ignored. Care must be taken to handle the case where the mode is non-unique.
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: averagespythagorean-means
|
||||
|
||||
# --description--
|
||||
|
||||
Compute all three of the [Pythagorean means](<https://en.wikipedia.org/wiki/Pythagorean means> "wp: Pythagorean means") of the set of integers $1$ through $10$ (inclusive).
|
||||
Compute all three of the [Pythagorean means](https://en.wikipedia.org/wiki/Pythagorean means "wp: Pythagorean means") of the set of integers $1$ through $10$ (inclusive).
|
||||
|
||||
Show that $A(x_1,\\ldots,x_n) \\geq G(x_1,\\ldots,x_n) \\geq H(x_1,\\ldots,x_n)$ for this set of positive integers.
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: averagesroot-mean-square
|
||||
|
||||
# --description--
|
||||
|
||||
Compute the [Root mean square](<https://en.wikipedia.org/wiki/Root mean square> "wp: Root mean square") of the numbers 1 through 10 inclusive.
|
||||
Compute the [Root mean square](https://en.wikipedia.org/wiki/Root mean square "wp: Root mean square") of the numbers 1 through 10 inclusive.
|
||||
|
||||
The *root mean square* is also known by its initials RMS (or rms), and as the **quadratic mean**.
|
||||
|
||||
|
@ -13,11 +13,11 @@ Determine whether a generated string of brackets is balanced; that is, whether i
|
||||
**Examples:**
|
||||
| Input | Output |
|
||||
| ------------------------- | ------ |
|
||||
| <code>\[]</code> | true |
|
||||
| <code>]\[</code> | false |
|
||||
| <code>[][]</code> | true |
|
||||
| <code>]\[]</code> | false |
|
||||
| <code>\[]]\[\[]</code> | false |
|
||||
| <code>\[]</code> | true |
|
||||
| <code>]\[</code> | false |
|
||||
| <code>[][]</code> | true |
|
||||
| <code>]\[]</code> | false |
|
||||
| <code>\[]]\[\[]</code> | false |
|
||||
| <code>\[\[\[\[]]]]</code> | true |
|
||||
|
||||
# --hints--
|
||||
|
@ -19,10 +19,10 @@ Demonstrate that it passes the following three test-cases:
|
||||
|
||||
<div style='font-size:115%; font-weight: bold;'>Test Cases</div>
|
||||
|
||||
| Input number | Output number |
|
||||
| ------------ | ------------------------------------- |
|
||||
| 7259 | <code>2 hr, 59 sec</code> |
|
||||
| 86400 | <code>1 d</code> |
|
||||
| Input number | Output number |
|
||||
| ------------ | ------------------------- |
|
||||
| 7259 | <code>2 hr, 59 sec</code> |
|
||||
| 86400 | <code>1 d</code> |
|
||||
| 6000000 | <code>9 wk, 6 d, 10 hr, 40 min</code> |
|
||||
|
||||
<div style="font-size:115%; font-weight: bold;">Details</div>
|
||||
@ -32,11 +32,11 @@ Demonstrate that it passes the following three test-cases:
|
||||
|
||||
| Unit | Suffix used in Output | Conversion |
|
||||
| ------ | --------------------- | --------------------- |
|
||||
| week | <code>wk</code> | 1 week = 7 days |
|
||||
| day | <code>d</code> | 1 day = 24 hours |
|
||||
| hour | <code>hr</code> | 1 hour = 60 minutes |
|
||||
| minute | <code>min</code> | 1 minute = 60 seconds |
|
||||
| second | <code>sec</code> | --- |
|
||||
| week |!!crwdBlockTags_18_sgaTkcolBdwrc!! | 1 week = 7 days |
|
||||
| day |!!crwdBlockTags_19_sgaTkcolBdwrc!! | 1 day = 24 hours |
|
||||
| hour |!!crwdBlockTags_20_sgaTkcolBdwrc!! | 1 hour = 60 minutes |
|
||||
| minute |!!crwdBlockTags_21_sgaTkcolBdwrc!! | 1 minute = 60 seconds |
|
||||
| second |!!crwdBlockTags_22_sgaTkcolBdwrc!! | --- |
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
@ -8,7 +8,7 @@ dashedName: cramers-rule
|
||||
|
||||
# --description--
|
||||
|
||||
In [linear algebra](<https://en.wikipedia.org/wiki/linear algebra> "wp: linear algebra"), [Cramer's rule](<https://en.wikipedia.org/wiki/Cramer's rule> "wp: Cramer's rule") is an explicit formula for the solution of a [system of linear equations](<https://en.wikipedia.org/wiki/system of linear equations> "wp: system of linear equations") with as many equations as unknowns, valid whenever the system has a unique solution. It expresses the solution in terms of the determinants of the (square) coefficient matrix and of matrices obtained from it by replacing one column by the vector of right hand sides of the equations.
|
||||
In [linear algebra](https://en.wikipedia.org/wiki/linear algebra "wp: linear algebra"), [Cramer's rule](https://en.wikipedia.org/wiki/Cramer's rule "wp: Cramer's rule") is an explicit formula for the solution of a [system of linear equations](https://en.wikipedia.org/wiki/system of linear equations "wp: system of linear equations") with as many equations as unknowns, valid whenever the system has a unique solution. It expresses the solution in terms of the determinants of the (square) coefficient matrix and of matrices obtained from it by replacing one column by the vector of right hand sides of the equations.
|
||||
|
||||
Given
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: cumulative-standard-deviation
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function that takes an array of numbers as parameter and returns the [standard deviation](<https://en.wikipedia.org/wiki/Standard Deviation>) of the series.
|
||||
Write a function that takes an array of numbers as parameter and returns the [standard deviation](https://en.wikipedia.org/wiki/Standard Deviation) of the series.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
@ -12,7 +12,7 @@ dashedName: deal-cards-for-freecell
|
||||
|
||||
As the game became popular, Jim Horne disclosed the algorithm, and other implementations of FreeCell began to reproduce the Microsoft deals. These deals are numbered from 1 to 32000. Newer versions from Microsoft have 1 million deals, numbered from 1 to 1000000; some implementations allow numbers outside that range.
|
||||
|
||||
The algorithm uses this [linear congruential generator](<https://rosettacode.org/wiki/linear congruential generator> "linear congruential generator") from Microsoft C:
|
||||
The algorithm uses this [linear congruential generator](https://rosettacode.org/wiki/linear congruential generator "linear congruential generator") from Microsoft C:
|
||||
|
||||
<ul>
|
||||
<li>$state_{n + 1} \equiv 214013 \times state_n + 2531011 \pmod{2^{31}}$</li>
|
||||
|
@ -8,7 +8,7 @@ dashedName: discordian-date
|
||||
|
||||
# --description--
|
||||
|
||||
Convert a given date from the [Gregorian calendar](<https://en.wikipedia.org/wiki/Gregorian calendar> "wp: Gregorian calendar") to the [Discordian calendar](<https://en.wikipedia.org/wiki/Discordian calendar> "wp: Discordian calendar").
|
||||
Convert a given date from the [Gregorian calendar](https://en.wikipedia.org/wiki/Gregorian calendar "wp: Gregorian calendar") to the [Discordian calendar](https://en.wikipedia.org/wiki/Discordian calendar "wp: Discordian calendar").
|
||||
|
||||
# --hints--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: dot-product
|
||||
|
||||
# --description--
|
||||
|
||||
Create a function, to compute the **[dot product](<https://en.wikipedia.org/wiki/Dot product>)**, also known as the **scalar product** of two vectors.
|
||||
Create a function, to compute the **[dot product](https://en.wikipedia.org/wiki/Dot product)**, also known as the **scalar product** of two vectors.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: euler-method
|
||||
|
||||
# --description--
|
||||
|
||||
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value. It is an explicit method for solving initial value problems (IVPs), as described in [the wikipedia page](<https://en.wikipedia.org/wiki/Euler method> "wp: Euler method").
|
||||
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value. It is an explicit method for solving initial value problems (IVPs), as described in [the wikipedia page](https://en.wikipedia.org/wiki/Euler method "wp: Euler method").
|
||||
|
||||
The ODE has to be provided in the following form:
|
||||
|
||||
@ -89,7 +89,7 @@ and compare with the analytical solution.
|
||||
<li>room temperature <big>$T_R$</big> shall be <code>20 °C</code></li>
|
||||
<li>cooling constant <big>$k$</big> shall be <code>0.07</code></li>
|
||||
<li>time interval to calculate shall be from <code>0 s</code> to <code>100 s</code></li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
First parameter to the function is initial time, second parameter is initial temperature, third parameter is elapsed time and fourth parameter is step size.
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: execute-a-markov-algorithm
|
||||
|
||||
# --description--
|
||||
|
||||
Create an interpreter for a [Markov Algorithm](<https://en.wikipedia.org/wiki/Markov algorithm> "wp: Markov algorithm").
|
||||
Create an interpreter for a [Markov Algorithm](https://en.wikipedia.org/wiki/Markov algorithm "wp: Markov algorithm").
|
||||
|
||||
Rules have the syntax:
|
||||
|
||||
|
@ -16,16 +16,16 @@ Below are links to each of the versions of RCBF.
|
||||
|
||||
An implementation need only properly implement the following instructions:
|
||||
|
||||
| Command | Description |
|
||||
| ----------------- | ---------------------------------------------------------------------------------- |
|
||||
| <code>></code> | Move the pointer to the right |
|
||||
| <code><</code> | Move the pointer to the left |
|
||||
| <code>+</code> | Increment the memory cell under the pointer |
|
||||
| <code>-</code> | Decrement the memory cell under the pointer |
|
||||
| <code>.</code> | Output the character signified by the cell at the pointer |
|
||||
| <code>,</code> | Input a character and store it in the cell at the pointer |
|
||||
| <code>\[</code> | Jump past the matching <code>]</code> if the cell under the pointer is 0 |
|
||||
| <code>]</code> | Jump back to the matching <code>\[</code> if the cell under the pointer is nonzero |
|
||||
| Command | Description |
|
||||
| ------------------------- | ------------------------------------------------------------------------------------------ |
|
||||
| <code>></code> | Move the pointer to the right |
|
||||
| <code><</code> | Move the pointer to the left |
|
||||
| <code>+</code> | Increment the memory cell under the pointer |
|
||||
| <code>-</code> | Decrement the memory cell under the pointer |
|
||||
| <code>.</code> | Output the character signified by the cell at the pointer |
|
||||
| <code>,</code> | Input a character and store it in the cell at the pointer |
|
||||
| <code>\[</code> | Jump past the matching <code>]</code> if the cell under the pointer is 0 |
|
||||
| <code>]</code> | Jump back to the matching <code>\[</code> if the cell under the pointer is nonzero |
|
||||
|
||||
Any cell size is allowed, EOF (*E*nd-*O*-*F*ile) support is optional, as is whether you have bounded or unbounded memory.
|
||||
|
||||
|
@ -12,7 +12,7 @@ A Mersenne number is a number in the form of <code>2<sup>P</sup>-1</code>.
|
||||
|
||||
If `P` is prime, the Mersenne number may be a Mersenne prime. (If `P` is not prime, the Mersenne number is also not prime.)
|
||||
|
||||
In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy, [Lucas-Lehmer test](<https://rosettacode.org/wiki/Lucas-Lehmer test> "Lucas-Lehmer test").
|
||||
In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy, [Lucas-Lehmer test](https://rosettacode.org/wiki/Lucas-Lehmer test "Lucas-Lehmer test").
|
||||
|
||||
There are very efficient algorithms for determining if a number divides <code>2<sup>P</sup>-1</code> (or equivalently, if <code>2<sup>P</sup> mod (the number) = 1</code>).
|
||||
|
||||
@ -48,7 +48,7 @@ Further properties of Mersenne numbers allow us to refine the process even more.
|
||||
|
||||
Any factor `q` of <code>2<sup>P</sup>-1</code> must be of the form `2kP+1`, `k` being a positive integer or zero. Furthermore, `q` must be `1` or `7 mod 8`.
|
||||
|
||||
Finally any potential factor `q` must be [prime](<https://rosettacode.org/wiki/Primality by Trial Division> "Primality by Trial Division").
|
||||
Finally any potential factor `q` must be [prime](https://rosettacode.org/wiki/Primality by Trial Division "Primality by Trial Division").
|
||||
|
||||
As in other trial division algorithms, the algorithm stops when `2kP+1 > sqrt(N)`.These primarily tests only work on Mersenne numbers where `P` is prime. For example, <code>M<sub>4</sub>=15</code> yields no factors using these techniques, but factors into 3 and 5, neither of which fit `2kP+1`.
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: farey-sequence
|
||||
|
||||
# --description--
|
||||
|
||||
The [Farey sequence](<https://en.wikipedia.org/wiki/Farey sequence> "wp: Farey sequence") <code>F<sub>n</sub></code> of order `n` is the sequence of completely reduced fractions between `0` and `1` which, when in lowest terms, have denominators less than or equal to `n`, arranged in order of increasing size.
|
||||
The [Farey sequence](https://en.wikipedia.org/wiki/Farey sequence "wp: Farey sequence") <code>F<sub>n</sub></code> of order `n` is the sequence of completely reduced fractions between `0` and `1` which, when in lowest terms, have denominators less than or equal to `n`, arranged in order of increasing size.
|
||||
|
||||
The *Farey sequence* is sometimes incorrectly called a *Farey series*.
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: fibonacci-n-step-number-sequences
|
||||
|
||||
# --description--
|
||||
|
||||
These number series are an expansion of the ordinary [Fibonacci sequence](<https://rosettacode.org/wiki/Fibonacci sequence> "Fibonacci sequence") where:
|
||||
These number series are an expansion of the ordinary [Fibonacci sequence](https://rosettacode.org/wiki/Fibonacci sequence "Fibonacci sequence") where:
|
||||
|
||||
<ol>
|
||||
<li>For $n = 2$ we have the Fibonacci sequence; with initial values $[1, 1]$ and $F_k^2 = F_{k-1}^2 + F_{k-2}^2$</li>
|
||||
@ -17,7 +17,7 @@ These number series are an expansion of the ordinary [Fibonacci sequence](<https
|
||||
<li>For general $n>2$ we have the Fibonacci $n$-step sequence - $F_k^n$; with initial values of the first $n$ values of the $(n-1)$'th Fibonacci $n$-step sequence $F_k^{n-1}$; and $k$'th value of this $n$'th sequence being $F_k^n = \sum_{i=1}^{(n)} {F_{k-i}^{(n)}}$</li>
|
||||
</ol>
|
||||
|
||||
For small values of $n$, [Greek numeric prefixes](<https://en.wikipedia.org/wiki/Number prefix#Greek_series> "wp: Number prefix#Greek_series") are sometimes used to individually name each series.
|
||||
For small values of $n$, [Greek numeric prefixes](https://en.wikipedia.org/wiki/Number prefix#Greek_series "wp: Number prefix#Greek_series") are sometimes used to individually name each series.
|
||||
|
||||
Fibonacci $n$-step sequences:
|
||||
|
||||
@ -33,7 +33,7 @@ Fibonacci $n$-step sequences:
|
||||
| 9 | nonanacci | 1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144 ... |
|
||||
| 10 | decanacci | 1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172 ... |
|
||||
|
||||
Allied sequences can be generated where the initial values are changed: The [Lucas series](<https://en.wikipedia.org/wiki/Lucas number> "wp: Lucas number") sums the two preceding values like the fibonacci series for $n=2$ but uses $\[2, 1]$ as its initial values.
|
||||
Allied sequences can be generated where the initial values are changed: The [Lucas series](https://en.wikipedia.org/wiki/Lucas number "wp: Lucas number") sums the two preceding values like the fibonacci series for $n=2$ but uses $\[2, 1]$ as its initial values.
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: fractran
|
||||
|
||||
# --description--
|
||||
|
||||
[FRACTRAN](https://en.wikipedia.org/wiki/FRACTRAN "wp: FRACTRAN") is a Turing-complete esoteric programming language invented by the mathematician [John Horton Conway](<https://en.wikipedia.org/wiki/John Horton Conway> "wp: John Horton Conway").
|
||||
[FRACTRAN](https://en.wikipedia.org/wiki/FRACTRAN "wp: FRACTRAN") is a Turing-complete esoteric programming language invented by the mathematician [John Horton Conway](https://en.wikipedia.org/wiki/John Horton Conway "wp: John Horton Conway").
|
||||
|
||||
A FRACTRAN program is an ordered list of positive fractions $P = (f_1, f_2, \\ldots, f_m)$, together with an initial positive integer input $n$.
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: gamma-function
|
||||
|
||||
# --description--
|
||||
|
||||
Implement one algorithm (or more) to compute the [Gamma](<https://en.wikipedia.org/wiki/Gamma function>) ($\\Gamma$) function (in the real field only).
|
||||
Implement one algorithm (or more) to compute the [Gamma](https://en.wikipedia.org/wiki/Gamma function) ($\\Gamma$) function (in the real field only).
|
||||
|
||||
The Gamma function can be defined as:
|
||||
|
||||
|
@ -8,11 +8,11 @@ dashedName: gray-code
|
||||
|
||||
# --description--
|
||||
|
||||
[Gray code](<https://en.wikipedia.org/wiki/Gray code>) is a form of binary encoding where transitions between consecutive numbers differ by only one bit.
|
||||
[Gray code](https://en.wikipedia.org/wiki/Gray code) 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 [Karnaugh maps](<https://en.wikipedia.org/wiki/Karnaugh map>) in order from left to right or top to bottom.
|
||||
It is also useful for generating inputs for [Karnaugh maps](https://en.wikipedia.org/wiki/Karnaugh map) in order from left to right or top to bottom.
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: hash-join
|
||||
|
||||
# --description--
|
||||
|
||||
An [inner join](https://en.wikipedia.org/wiki/Join_(SQL)#Inner_join "wp: Join\_(SQL)#Inner_join") is an operation that combines two data tables into one table, based on matching column values. The simplest way of implementing this operation is the [nested loop join](<https://en.wikipedia.org/wiki/Nested loop join> "wp: Nested loop join") algorithm, but a more scalable alternative is the [hash join](<https://en.wikipedia.org/wiki/hash join> "wp: hash join") algorithm.
|
||||
An [inner join](https://en.wikipedia.org/wiki/Join_(SQL)#Inner_join "wp: Join\_(SQL)#Inner_join") is an operation that combines two data tables into one table, based on matching column values. The simplest way of implementing this operation is the [nested loop join](https://en.wikipedia.org/wiki/Nested loop join "wp: Nested loop join") algorithm, but a more scalable alternative is the [hash join](https://en.wikipedia.org/wiki/hash join "wp: hash join") algorithm.
|
||||
|
||||
The "hash join" algorithm consists of two steps:
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: heronian-triangles
|
||||
|
||||
# --description--
|
||||
|
||||
[Hero's formula](<https://en.wikipedia.org/wiki/Heron's formula> "wp: Heron's formula") for the area of a triangle given the length of its three sides `a`, `b`, and `c` is given by:
|
||||
[Hero's formula](https://en.wikipedia.org/wiki/Heron's formula "wp: Heron's formula") for the area of a triangle given the length of its three sides `a`, `b`, and `c` is given by:
|
||||
|
||||
$A = \\sqrt{s(s-a)(s-b)(s-c)},$
|
||||
|
||||
|
@ -12,7 +12,7 @@ The [Hofstadter Q sequence](https://en.wikipedia.org/wiki/Hofstadter_sequence#Ho
|
||||
|
||||
$Q(1)=Q(2)=1, \\\\ Q(n)=Q\\big(n-Q(n-1)\\big)+Q\\big(n-Q(n-2)), \\quad n>2.$
|
||||
|
||||
It is defined like the [Fibonacci sequence](<https://rosettacode.org/wiki/Fibonacci sequence> "Fibonacci sequence"), but whereas the next term in the Fibonacci sequence is the sum of the previous two terms, in the Q sequence the previous two terms tell you how far to go back in the Q sequence to find the two numbers to sum to make the next term of the sequence.
|
||||
It is defined like the [Fibonacci sequence](https://rosettacode.org/wiki/Fibonacci sequence "Fibonacci sequence"), but whereas the next term in the Fibonacci sequence is the sum of the previous two terms, in the Q sequence the previous two terms tell you how far to go back in the Q sequence to find the two numbers to sum to make the next term of the sequence.
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: i-before-e-except-after-c
|
||||
|
||||
# --description--
|
||||
|
||||
The phrase ["I before E, except after C"](<https://en.wikipedia.org/wiki/I before E except after C>) is a widely known mnemonic which is supposed to help when spelling English words.
|
||||
The phrase ["I before E, except after C"](https://en.wikipedia.org/wiki/I before E except after C) is a widely known mnemonic which is supposed to help when spelling English words.
|
||||
|
||||
Using the words provided, check if the two sub-clauses of the phrase are plausible individually:
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: josephus-problem
|
||||
|
||||
# --description--
|
||||
|
||||
[Josephus problem](<https://en.wikipedia.org/wiki/Josephus problem>) is a math puzzle with a grim description: $n$ prisoners are standing on a circle, sequentially numbered from $0$ to $n-1$.
|
||||
[Josephus problem](https://en.wikipedia.org/wiki/Josephus problem) is a math puzzle with a grim description: $n$ prisoners are standing on a circle, sequentially numbered from $0$ to $n-1$.
|
||||
|
||||
An executioner walks along the circle, starting from prisoner $0$, removing every $k$-th prisoner and killing him.
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: kaprekar-numbers
|
||||
|
||||
# --description--
|
||||
|
||||
A positive integer is a [Kaprekar number](<https://en.wikipedia.org/wiki/Kaprekar number>) if:
|
||||
A positive integer is a [Kaprekar number](https://en.wikipedia.org/wiki/Kaprekar number) if:
|
||||
|
||||
<ul>
|
||||
<li>It is 1, or,</li>
|
||||
|
@ -8,7 +8,7 @@ dashedName: least-common-multiple
|
||||
|
||||
# --description--
|
||||
|
||||
The least common multiple of 12 and 18 is 36, because 12 is a factor (12 × 3 = 36), and 18 is a factor (18 × 2 = 36), and there is no positive integer less than 36 that has both factors. As a special case, if either *m* or *n* is zero, then the least common multiple is zero. One way to calculate the least common multiple is to iterate all the multiples of *m*, until you find one that is also a multiple of *n*. If you already have *gcd* for [greatest common divisor](<https://rosettacode.org/wiki/greatest common divisor>), then this formula calculates *lcm*. ( \\operatorname{lcm}(m, n) = \\frac{|m \\times n|}{\\operatorname{gcd}(m, n)} )
|
||||
The least common multiple of 12 and 18 is 36, because 12 is a factor (12 × 3 = 36), and 18 is a factor (18 × 2 = 36), and there is no positive integer less than 36 that has both factors. As a special case, if either *m* or *n* is zero, then the least common multiple is zero. One way to calculate the least common multiple is to iterate all the multiples of *m*, until you find one that is also a multiple of *n*. If you already have *gcd* for [greatest common divisor](https://rosettacode.org/wiki/greatest common divisor), then this formula calculates *lcm*. ( \\operatorname{lcm}(m, n) = \\frac{|m \\times n|}{\\operatorname{gcd}(m, n)} )
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: levenshtein-distance
|
||||
|
||||
# --description--
|
||||
|
||||
In information theory and computer science, the **Levenshtein distance** is a [metric](<https://en.wikipedia.org/wiki/string metric>) for measuring the amount of difference between two sequences (i.e. an [edit distance](<https://en.wikipedia.org/wiki/edit distance>)). The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character.
|
||||
In information theory and computer science, the **Levenshtein distance** is a [metric](https://en.wikipedia.org/wiki/string metric) for measuring the amount of difference between two sequences (i.e. an [edit distance](https://en.wikipedia.org/wiki/edit distance)). The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character.
|
||||
|
||||
Example:
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: linear-congruential-generator
|
||||
|
||||
# --description--
|
||||
|
||||
The [linear congruential generator](<https://en.wikipedia.org/wiki/linear congruential generator>) is a very simple example of a [random number generator](<http://rosettacode.org/wiki/random number generator>). All linear congruential generators use this formula:
|
||||
The [linear congruential generator](https://en.wikipedia.org/wiki/linear congruential generator) is a very simple example of a [random number generator](http://rosettacode.org/wiki/random number generator). All linear congruential generators use this formula:
|
||||
|
||||
$$r_{n + 1} = (a \times r_n + c) \bmod m$$
|
||||
|
||||
@ -22,7 +22,7 @@ Where:
|
||||
|
||||
If one chooses the values of $a$, $c$ and $m$ with care, then the generator produces a uniform distribution of integers from $0$ to $m - 1$.
|
||||
|
||||
LCG numbers have poor quality. $r_n$ and $r\_{n + 1}$ are not independent, as true random numbers would be. Anyone who knows $r_n$ can predict $r\_{n + 1}$, therefore LCG is not cryptographically secure. The LCG is still good enough for simple tasks like [Miller-Rabin primality test](<http://rosettacode.org/wiki/Miller-Rabin primality test>), or [FreeCell deals](<http://rosettacode.org/wiki/deal cards for FreeCell>). Among the benefits of the LCG, one can easily reproduce a sequence of numbers, from the same $r_0$. One can also reproduce such sequence with a different programming language, because the formula is so simple.
|
||||
LCG numbers have poor quality. $r_n$ and $r\_{n + 1}$ are not independent, as true random numbers would be. Anyone who knows $r_n$ can predict $r\_{n + 1}$, therefore LCG is not cryptographically secure. The LCG is still good enough for simple tasks like [Miller-Rabin primality test](http://rosettacode.org/wiki/Miller-Rabin primality test), or [FreeCell deals](http://rosettacode.org/wiki/deal cards for FreeCell). Among the benefits of the LCG, one can easily reproduce a sequence of numbers, from the same $r_0$. One can also reproduce such sequence with a different programming language, because the formula is so simple.
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: long-multiplication
|
||||
|
||||
# --description--
|
||||
|
||||
Explicitly implement [long multiplication](<https://en.wikipedia.org/wiki/long multiplication>).
|
||||
Explicitly implement [long multiplication](https://en.wikipedia.org/wiki/long multiplication).
|
||||
|
||||
This is one possible approach to arbitrary-precision integer algebra.
|
||||
|
||||
|
@ -18,7 +18,7 @@ Longest increasing sequence is:
|
||||
|
||||
$\\{3, 10, 20\\}$
|
||||
|
||||
For more information on this problem please see [Wikipedia](<https://en.wikipedia.org/wiki/Longest increasing subsequence>).
|
||||
For more information on this problem please see [Wikipedia](https://en.wikipedia.org/wiki/Longest increasing subsequence).
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: look-and-say-sequence
|
||||
|
||||
# --description--
|
||||
|
||||
The [Look and say sequence](<https://en.wikipedia.org/wiki/Look and say sequence>) is a recursively defined sequence of numbers.
|
||||
The [Look and say sequence](https://en.wikipedia.org/wiki/Look and say sequence) is a recursively defined sequence of numbers.
|
||||
|
||||
Sequence Definition
|
||||
|
||||
|
@ -8,13 +8,13 @@ dashedName: lu-decomposition
|
||||
|
||||
# --description--
|
||||
|
||||
Every square matrix $A$ can be decomposed into a product of a lower triangular matrix $L$ and a upper triangular matrix $U$, as described in [LU decomposition](<https://en.wikipedia.org/wiki/LU decomposition>).
|
||||
Every square matrix $A$ can be decomposed into a product of a lower triangular matrix $L$ and a upper triangular matrix $U$, as described in [LU decomposition](https://en.wikipedia.org/wiki/LU decomposition).
|
||||
|
||||
$A = LU$
|
||||
|
||||
It is a modified form of Gaussian elimination.
|
||||
|
||||
While the [Cholesky decomposition](<http://rosettacode.org/wiki/Cholesky decomposition>) only works for symmetric, positive definite matrices, the more general LU decomposition works for any square matrix.
|
||||
While the [Cholesky decomposition](http://rosettacode.org/wiki/Cholesky decomposition) only works for symmetric, positive definite matrices, the more general LU decomposition works for any square matrix.
|
||||
|
||||
There are several algorithms for calculating $L$ and $U$.
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: luhn-test-of-credit-card-numbers
|
||||
|
||||
# --description--
|
||||
|
||||
The [Luhn test](<https://en.wikipedia.org/wiki/Luhn algorithm>) is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits.
|
||||
The [Luhn test](https://en.wikipedia.org/wiki/Luhn algorithm) is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits.
|
||||
|
||||
Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test:
|
||||
|
||||
|
@ -89,7 +89,7 @@ function isSelfDescribing(n) {
|
||||
if (digits.length != count.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
for (let i=0; i< digits.length; i++){
|
||||
if (digits[i] !== count[i]) {
|
||||
return false;
|
||||
|
@ -8,7 +8,7 @@ dashedName: self-referential-sequence
|
||||
|
||||
# --description--
|
||||
|
||||
There are several ways to generate a self-referential sequence. One very common one (the [Look-and-say sequence](<https://rosettacode.org/wiki/Look-and-say sequence>)) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits:
|
||||
There are several ways to generate a self-referential sequence. One very common one (the [Look-and-say sequence](https://rosettacode.org/wiki/Look-and-say sequence)) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits:
|
||||
|
||||
<pre>0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ...</pre>
|
||||
|
||||
|
@ -8,8 +8,7 @@ dashedName: sha-256
|
||||
|
||||
# --description--
|
||||
|
||||
The `SHA-2` family is a stronger alternative to `SHA-1`. The main difference between them is the length of the hash.
|
||||
Meaning `SHA-1` provides a shorter code with fewer possibilities for unique combinations. `SHA-2` or `SHA-256` creates a longer and thus more complex hash with more possibilities.
|
||||
The `SHA-2` family is a stronger alternative to `SHA-1`. The main difference between them is the length of the hash. Meaning `SHA-1` provides a shorter code with fewer possibilities for unique combinations. `SHA-2` or `SHA-256` creates a longer and thus more complex hash with more possibilities.
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: sorting-algorithmscocktail-sort
|
||||
|
||||
# --description--
|
||||
|
||||
The cocktail shaker sort is an improvement on the [Bubble Sort](<https://rosettacode.org/wiki/Bubble Sort>). The improvement is basically that values "bubble" both directions through the array, because on each iteration the cocktail shaker sort bubble sorts once forwards and once backwards. Pseudocode for the algorithm (from [wikipedia](<https://en.wikipedia.org/wiki/Cocktail sort>)):
|
||||
The cocktail shaker sort is an improvement on the [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort). The improvement is basically that values "bubble" both directions through the array, because on each iteration the cocktail shaker sort bubble sorts once forwards and once backwards. Pseudocode for the algorithm (from [wikipedia](https://en.wikipedia.org/wiki/Cocktail sort)):
|
||||
|
||||
<pre><b>function</b> <i>cocktailSort</i>( A : list of sortable items )
|
||||
<b>do</b>
|
||||
|
@ -10,9 +10,9 @@ dashedName: sorting-algorithmscomb-sort
|
||||
|
||||
Implement a *comb sort*.
|
||||
|
||||
The **Comb Sort** is a variant of the [Bubble Sort](<https://rosettacode.org/wiki/Bubble Sort>).
|
||||
The **Comb Sort** is a variant of the [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort).
|
||||
|
||||
Like the [Shell sort](<https://rosettacode.org/wiki/Shell sort>), the Comb Sort increases the gap used in comparisons and exchanges.
|
||||
Like the [Shell sort](https://rosettacode.org/wiki/Shell sort), the Comb Sort increases the gap used in comparisons and exchanges.
|
||||
|
||||
Dividing the gap by $(1-e^{-\\varphi})^{-1} \\approx 1.247330950103979$ works best, but 1.3 may be more practical.
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: sorting-algorithmsgnome-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Gnome sort is a sorting algorithm which is similar to [Insertion sort](<https://rosettacode.org/wiki/Insertion sort>), except that moving an element to its proper place is accomplished by a series of swaps, as in [Bubble Sort](<https://rosettacode.org/wiki/Bubble Sort>).
|
||||
Gnome sort is a sorting algorithm which is similar to [Insertion sort](https://rosettacode.org/wiki/Insertion sort), except that moving an element to its proper place is accomplished by a series of swaps, as in [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort).
|
||||
|
||||
The pseudocode for the algorithm is:
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: sorting-algorithmspancake-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to sort an array of integers (of any convenient size) into ascending order using [Pancake sorting](<https://en.wikipedia.org/wiki/Pancake sorting>). The function should return the sorted array.
|
||||
Write a function to sort an array of integers (of any convenient size) into ascending order using [Pancake sorting](https://en.wikipedia.org/wiki/Pancake sorting). The function should return the sorted array.
|
||||
|
||||
In short, instead of individual elements being sorted, the only operation allowed is to "flip" one end of the list, like so:
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: sorting-algorithmsshell-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to sort an array of elements using the [Shell sort](<https://en.wikipedia.org/wiki/Shell sort>) algorithm, a diminishing increment sort. The function should return the sorted array.
|
||||
Write a function to sort an array of elements using the [Shell sort](https://en.wikipedia.org/wiki/Shell sort) algorithm, a diminishing increment sort. The function should return the sorted array.
|
||||
|
||||
The Shell sort (also known as Shellsort or Shell's method) is named after its inventor, Donald Shell, who published the algorithm in 1959.
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: sorting-algorithmsstooge-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to perform [Stooge Sort](<https://en.wikipedia.org/wiki/Stooge sort>) on an array of integers. The function should return a sorted array.
|
||||
Write a function to perform [Stooge Sort](https://en.wikipedia.org/wiki/Stooge sort) on an array of integers. The function should return a sorted array.
|
||||
|
||||
The Stooge Sort algorithm is as follows:
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: sorting-algorithmsstrand-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to sort an array using the [Strand sort](<https://en.wikipedia.org/wiki/Strand sort>). The function should return the sorted array.
|
||||
Write a function to sort an array using the [Strand sort](https://en.wikipedia.org/wiki/Strand sort). The function should return the sorted array.
|
||||
|
||||
This is a way of sorting numbers by extracting shorter sequences of already sorted numbers from an unsorted list.
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: stern-brocot-sequence
|
||||
|
||||
# --description--
|
||||
|
||||
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the [Fibonacci sequence](<https://rosettacode.org/wiki/Fibonacci sequence>).
|
||||
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the [Fibonacci sequence](https://rosettacode.org/wiki/Fibonacci sequence).
|
||||
|
||||
<ol>
|
||||
<li>The first and second members of the sequence are both 1:</li>
|
||||
|
@ -8,7 +8,7 @@ dashedName: sum-of-a-series
|
||||
|
||||
# --description--
|
||||
|
||||
Compute the **n**<sup>th</sup> term of a [series](<https://en.wikipedia.org/wiki/Series (mathematics)>), i.e. the sum of the **n** first terms of the corresponding [sequence](https://en.wikipedia.org/wiki/sequence). Informally this value, or its limit when **n** tends to infinity, is also called the *sum of the series*, thus the title of this task. For this task, use: $S_n = \displaystyle\sum_{k=1}^n \frac{1}{k^2}$.
|
||||
Compute the **n**<sup>th</sup> term of a [series](https://en.wikipedia.org/wiki/Series (mathematics)), i.e. the sum of the **n** first terms of the corresponding [sequence](https://en.wikipedia.org/wiki/sequence). Informally this value, or its limit when **n** tends to infinity, is also called the *sum of the series*, thus the title of this task. For this task, use: $S_n = \displaystyle\sum_{k=1}^n \frac{1}{k^2}$.
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: sutherland-hodgman-polygon-clipping
|
||||
|
||||
# --description--
|
||||
|
||||
The [Sutherland-Hodgman clipping algorithm](<https://en.wikipedia.org/wiki/Sutherland-Hodgman clipping algorithm>) finds the polygon that is the intersection between an arbitrary polygon (the "subject polygon") and a convex polygon (the "clip polygon"). It is used in computer graphics (especially 2D graphics) to reduce the complexity of a scene being displayed by eliminating parts of a polygon that do not need to be displayed. Take the closed polygon defined by the points:
|
||||
The [Sutherland-Hodgman clipping algorithm](https://en.wikipedia.org/wiki/Sutherland-Hodgman clipping algorithm) finds the polygon that is the intersection between an arbitrary polygon (the "subject polygon") and a convex polygon (the "clip polygon"). It is used in computer graphics (especially 2D graphics) to reduce the complexity of a scene being displayed by eliminating parts of a polygon that do not need to be displayed. Take the closed polygon defined by the points:
|
||||
|
||||
<pre>[(50, 150), (200, 50), (350, 150), (350, 300), (250, 300), (200, 250), (150, 350), (100, 250), (100, 200)]</pre>
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: symmetric-difference
|
||||
|
||||
# --description--
|
||||
|
||||
Given two [set](https://rosettacode.org/wiki/set)s *A* and *B*, compute $(A \\setminus B) \\cup (B \\setminus A).$ That is, enumerate the items that are in *A* or *B* but not both. This set is called the [symmetric difference](<https://en.wikipedia.org/wiki/Symmetric difference>) of *A* and *B*. In other words: $(A \\cup B) \\setminus (A \\cap B)$ (the set of items that are in at least one of *A* or *B* minus the set of items that are in both *A* and *B*).
|
||||
Given two [set](https://rosettacode.org/wiki/set)s *A* and *B*, compute $(A \\setminus B) \\cup (B \\setminus A).$ That is, enumerate the items that are in *A* or *B* but not both. This set is called the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric difference) of *A* and *B*. In other words: $(A \\cup B) \\setminus (A \\cap B)$ (the set of items that are in at least one of *A* or *B* minus the set of items that are in both *A* and *B*).
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: taxicab-numbers
|
||||
|
||||
# --description--
|
||||
|
||||
A [taxicab number](<https://en.wikipedia.org/wiki/Hardy–Ramanujan number> "wp: Hardy–Ramanujan number") (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.
|
||||
A [taxicab number](https://en.wikipedia.org/wiki/Hardy–Ramanujan number "wp: Hardy–Ramanujan number") (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 `1729`, which is:
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: y-combinator
|
||||
|
||||
# --description--
|
||||
|
||||
In strict [functional programming](<https://en.wikipedia.org/wiki/Functional programming> "wp: functional programming") and the [lambda calculus](<https://en.wikipedia.org/wiki/lambda calculus> "wp: lambda calculus"), functions (lambda expressions) don't have state and are only allowed to refer to arguments of enclosing functions. This rules out the usual definition of a recursive function wherein a function is associated with the state of a variable and this variable's state is used in the body of the function. The [Y combinator](https://mvanier.livejournal.com/2897.html) is itself a stateless function that, when applied to another stateless function, returns a recursive version of the function. The Y combinator is the simplest of the class of such functions, called [fixed-point combinators](<https://en.wikipedia.org/wiki/Fixed-point combinator> "wp: fixed-point combinator").
|
||||
In strict [functional programming](https://en.wikipedia.org/wiki/Functional programming "wp: functional programming") and the [lambda calculus](https://en.wikipedia.org/wiki/lambda calculus "wp: lambda calculus"), functions (lambda expressions) don't have state and are only allowed to refer to arguments of enclosing functions. This rules out the usual definition of a recursive function wherein a function is associated with the state of a variable and this variable's state is used in the body of the function. The [Y combinator](https://mvanier.livejournal.com/2897.html) is itself a stateless function that, when applied to another stateless function, returns a recursive version of the function. The Y combinator is the simplest of the class of such functions, called [fixed-point combinators](https://en.wikipedia.org/wiki/Fixed-point combinator "wp: fixed-point combinator").
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -10,77 +10,56 @@ dashedName: zhang-suen-thinning-algorithm
|
||||
|
||||
This is an algorithm used to thin a black and white i.e. one bit per pixel images. For example, with an input image of:
|
||||
|
||||
<!-- TODO write fully in markdown>
|
||||
<!-- markdownlint-disable -->
|
||||
|
||||
<pre>
|
||||
################# #############
|
||||
################## ################
|
||||
################### ##################
|
||||
######## ####### ###################
|
||||
###### ####### ####### ######
|
||||
###### ####### #######
|
||||
################# #######
|
||||
################ #######
|
||||
################# #######
|
||||
###### ####### #######
|
||||
###### ####### #######
|
||||
###### ####### ####### ######
|
||||
######## ####### ###################
|
||||
######## ####### ###### ################## ######
|
||||
######## ####### ###### ################ ######
|
||||
######## ####### ###### ############# ######
|
||||
</pre>
|
||||
```js
|
||||
const testImage1 = [
|
||||
' ',
|
||||
'######### ######## ',
|
||||
'### #### #### #### ',
|
||||
'### ### ### ### ',
|
||||
'### #### ### ',
|
||||
'######### ### ',
|
||||
'### #### ### ### ',
|
||||
'### #### ### #### #### ### ',
|
||||
'### #### ### ######## ### ',
|
||||
' '
|
||||
];
|
||||
```
|
||||
|
||||
It produces the thinned output:
|
||||
|
||||
<pre>
|
||||
```js
|
||||
[ ' ',
|
||||
'######## ###### ',
|
||||
'# # ## ',
|
||||
'# # # ',
|
||||
'# # # ',
|
||||
'###### # # ',
|
||||
'# ## # ',
|
||||
'# # # ## ## # ',
|
||||
'# # #### ',
|
||||
' ' ];
|
||||
```
|
||||
|
||||
# ########## #######
|
||||
## # #### #
|
||||
# # ##
|
||||
# # #
|
||||
# # #
|
||||
# # #
|
||||
############ #
|
||||
# # #
|
||||
# # #
|
||||
# # #
|
||||
# # #
|
||||
# ##
|
||||
# ############
|
||||
### ###
|
||||
|
||||
</pre>
|
||||
|
||||
<h2>Algorithm</h2>
|
||||
## Algorithm
|
||||
|
||||
Assume black pixels are one and white pixels zero, and that the input image is a rectangular N by M array of ones and zeroes. The algorithm operates on all black pixels P1 that can have eight neighbours. The neighbours are, in order, arranged as:
|
||||
|
||||
<table border="3">
|
||||
<tr><td style="text-align: center;">P9</td><td style="text-align: center;">P2</td><td style="text-align: center;">P3</td></tr>
|
||||
<tr><td style="text-align: center;">P8</td><td style="text-align: center;"><strong>P1</strong></td><td style="text-align: center;">P4</td></tr>
|
||||
<tr><td style="text-align: center;">P7</td><td style="text-align: center;">P6</td><td style="text-align: center;">P5</td></tr>
|
||||
</table>
|
||||
$$\begin{array}{|c|c|c|} \\hline P9 & P2 & P3\\\\ \\hline P8 & \boldsymbol{P1} & P4\\\\ \\hline P7 & P6 & P5\\\\ \\hline \end{array}$$
|
||||
|
||||
Obviously the boundary pixels of the image cannot have the full eight neighbours.
|
||||
|
||||
<ul>
|
||||
<li>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).</li>
|
||||
<li>Define $B(P1)$ = the number of black pixel neighbours of P1. ( = sum(P2 .. P9) )</li>
|
||||
</ul>
|
||||
- Define $A(P1)$ = the number of transitions from white to black, ($0 \to 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 \ldots P9)$)
|
||||
|
||||
**Step 1:**
|
||||
|
||||
All pixels are tested and pixels satisfying all the following conditions (simultaneously) are just noted at this stage.
|
||||
|
||||
<ol>
|
||||
<li>The pixel is black and has eight neighbours</li>
|
||||
<li>$2 <= B(P1) <= 6$</li>
|
||||
<li>$A(P1) = 1$</li>
|
||||
<li>At least one of <strong>P2, P4 and P6</strong> is white</li>
|
||||
<li>At least one of <strong>P4, P6 and P8</strong> is white</li>
|
||||
</ol>
|
||||
1. The pixel is black and has eight neighbours
|
||||
2. $2 \le B(P1) \le 6$
|
||||
3. $A(P1) = 1$
|
||||
4. At least one of $P2$, $P4$ and $P6$ is white
|
||||
5. At least one of $P4$, $P6$ and $P8$ is white
|
||||
|
||||
After iterating over the image and collecting all the pixels satisfying all step 1 conditions, all these condition satisfying pixels are set to white.
|
||||
|
||||
@ -88,14 +67,12 @@ After iterating over the image and collecting all the pixels satisfying all step
|
||||
|
||||
All pixels are again tested and pixels satisfying all the following conditions are just noted at this stage.
|
||||
|
||||
<ol>
|
||||
<li>The pixel is black and has eight neighbours</li>
|
||||
<li>$2 <= B(P1) <= 6$</li>
|
||||
<li>$A(P1) = 1$</li>
|
||||
<li>At least one of <strong>P2, P4 and P8</strong> is white</li>
|
||||
<li>At least one of <strong>P2, P6 and P8</strong> is white</li>
|
||||
</ol>
|
||||
|
||||
1. The pixel is black and has eight neighbours
|
||||
2. $2 \le B(P1) \le 6$
|
||||
3. $A(P1) = 1$
|
||||
4. At least one of $P2$, $P4$ and $P8$ is white
|
||||
5. At least one of $P2$, $P6$ and $P8$ is white
|
||||
|
||||
After iterating over the image and collecting all the pixels satisfying all step 2 conditions, all these condition satisfying pixels are again set to white.
|
||||
|
||||
**Iteration:**
|
||||
@ -104,7 +81,7 @@ If any pixels were set in this round of either step 1 or step 2 then all steps a
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a routine to perform Zhang-Suen thinning on the provided image matrix.
|
||||
Write a routine to perform Zhang-Suen thinning on the provided `image`, an array of strings, where each string represents single line of the image. In the string, `#` represents black pixel, and whitespace represents white pixel. Function should return thinned image, using the same representation.
|
||||
|
||||
# --hints--
|
||||
|
||||
@ -117,19 +94,25 @@ assert.equal(typeof thinImage, 'function');
|
||||
`thinImage` should return an array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(result));
|
||||
assert(Array.isArray(thinImage(_testImage1)));
|
||||
```
|
||||
|
||||
`thinImage` should return an array of strings.
|
||||
|
||||
```js
|
||||
assert.equal(typeof result[0], 'string');
|
||||
assert.equal(typeof thinImage(_testImage1)[0], 'string');
|
||||
```
|
||||
|
||||
`thinImage` should return an array of strings.
|
||||
`thinImage(testImage1)` should return a thinned image as in the example.
|
||||
|
||||
```js
|
||||
assert.deepEqual(result, expected);
|
||||
assert.deepEqual(thinImage(_testImage1), expected1);
|
||||
```
|
||||
|
||||
`thinImage(testImage2)` should return a thinned image.
|
||||
|
||||
```js
|
||||
assert.deepEqual(thinImage(_testImage2), expected2);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -137,7 +120,31 @@ assert.deepEqual(result, expected);
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
const imageForTests = [
|
||||
const _testImage1 = [
|
||||
' ',
|
||||
'######### ######## ',
|
||||
'### #### #### #### ',
|
||||
'### ### ### ### ',
|
||||
'### #### ### ',
|
||||
'######### ### ',
|
||||
'### #### ### ### ',
|
||||
'### #### ### #### #### ### ',
|
||||
'### #### ### ######## ### ',
|
||||
' '
|
||||
];
|
||||
const expected1 = [
|
||||
' ',
|
||||
'######## ###### ',
|
||||
'# # ## ',
|
||||
'# # # ',
|
||||
'# # # ',
|
||||
'###### # # ',
|
||||
'# ## # ',
|
||||
'# # # ## ## # ',
|
||||
'# # #### ',
|
||||
' '
|
||||
];
|
||||
const _testImage2 = [
|
||||
' ',
|
||||
' ################# ############# ',
|
||||
' ################## ################ ',
|
||||
@ -156,7 +163,7 @@ const imageForTests = [
|
||||
' ######## ####### ###### ################ ###### ',
|
||||
' ######## ####### ###### ############# ###### ',
|
||||
' '];
|
||||
const expected = [
|
||||
const expected2 = [
|
||||
' ',
|
||||
' ',
|
||||
' # ########## ####### ',
|
||||
@ -176,35 +183,27 @@ const expected = [
|
||||
' ',
|
||||
' '
|
||||
];
|
||||
const result = thinImage(imageForTests);
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
const testImage = [
|
||||
' ',
|
||||
' ################# ############# ',
|
||||
' ################## ################ ',
|
||||
' ################### ################## ',
|
||||
' ######## ####### ################### ',
|
||||
' ###### ####### ####### ###### ',
|
||||
' ###### ####### ####### ',
|
||||
' ################# ####### ',
|
||||
' ################ ####### ',
|
||||
' ################# ####### ',
|
||||
' ###### ####### ####### ',
|
||||
' ###### ####### ####### ',
|
||||
' ###### ####### ####### ###### ',
|
||||
' ######## ####### ################### ',
|
||||
' ######## ####### ###### ################## ###### ',
|
||||
' ######## ####### ###### ################ ###### ',
|
||||
' ######## ####### ###### ############# ###### ',
|
||||
' '];
|
||||
|
||||
function thinImage(image) {
|
||||
|
||||
}
|
||||
|
||||
const testImage1 = [
|
||||
' ',
|
||||
'######### ######## ',
|
||||
'### #### #### #### ',
|
||||
'### ### ### ### ',
|
||||
'### #### ### ',
|
||||
'######### ### ',
|
||||
'### #### ### ### ',
|
||||
'### #### ### #### #### ### ',
|
||||
'### #### ### ######## ### ',
|
||||
' '
|
||||
];
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
Reference in New Issue
Block a user