Changed bold to strong or code tags where possible

This commit is contained in:
Kris Koishigawa
2019-06-14 20:04:16 +09:00
committed by mrugesh
parent 3ce97bbd81
commit 1028310819
40 changed files with 175 additions and 177 deletions

View File

@ -7,7 +7,7 @@ challengeType: 5
## Description
<section id='description'>
These define three classifications of positive integers based on their <a href='https://rosettacode.org/wiki/Proper divisors' title='Proper divisors' target='_blank'>proper divisors</a>.
Let $P(n)$ be the sum of the proper divisors of <b>n</b> where proper divisors are all positive integers <b>n</b> other than <b>n</b> itself.
Let $P(n)$ be the sum of the proper divisors of <code>n</code> where proper divisors are all positive integers <code>n</code> other than <code>n</code> itself.
If <code>P(n) < n</code> then <code>n</code> is classed as <code>deficient</code>
@ -16,13 +16,13 @@ If <code>P(n) === n</code> then <code>n</code> is classed as <code>perfect</code
If <code>P(n) > n</code> then <code>n</code> is classed as <code>abundant</code>
<strong>Example</strong>:
<strong>6</strong> has proper divisors of <strong>1</strong>, <strong>2</strong>, and <strong>3</strong>.
<strong>1 + 2 + 3 = 6</strong>, so <strong>6</strong> is classed as a perfect number.
<code>6</code> has proper divisors of <code>1</code>, <code>2</code>, and <code>3</code>.
<code>1 + 2 + 3 = 6</code>, so <code>6</code> is classed as a perfect number.
</section>
## Instructions
<section id='instructions'>
Implement a function that calculates how many of the integers from <b>1</b> to <b>20,000</b> (inclusive) are in each of the three classes. Output the result as an array in the following format <code>[deficient, perfect, abundant]</code>.
Implement a function that calculates how many of the integers from <code>1</code> to <code>20,000</code> (inclusive) are in each of the three classes. Output the result as an array in the following format <code>[deficient, perfect, abundant]</code>.
</section>
## Tests

View File

@ -12,9 +12,9 @@ A problem posed by <a href='https://en.wikipedia.org/wiki/Paul_Graham_(programme
## Instructions
<section id='instructions'>
Create a function that takes a number $n$ and generates accumulator functions that return the sum of every number ever passed to them.
<b>Rules:</b>
<strong>Rules:</strong>
Do not use global variables.
<b>Hint:</b>
<strong>Hint:</strong>
Closures save outer state.
</section>

View File

@ -7,7 +7,7 @@ challengeType: 5
## Description
<section id='description'>
Compute the <a href="https://en.wikipedia.org/wiki/Root mean square" title="wp: Root mean square" target='_blank'>Root mean square</a> of the numbers 1 through 10 inclusive.
The <i>root mean square</i> is also known by its initials RMS (or rms), and as the <b>quadratic mean</b>.
The <i>root mean square</i> is also known by its initials RMS (or rms), and as the <strong>quadratic mean</strong>.
The RMS is calculated as the mean of the squares of the numbers, square-rooted:
<big>$$x_{\mathrm{rms}} = \sqrt {{{x_1}^2 + {x_2}^2 + \cdots + {x_n}^2} \over n}. $$</big>
</section>

View File

@ -7,7 +7,7 @@ challengeType: 5
## Description
<section id='description'>
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
<b>Exceptions:</b>
<strong>Exceptions:</strong>
<ul>
<li>A radius of zero should be treated as never describing circles (except in the case where the points are coincident).</li>
<li>If the points are coincident then an infinite number of circles with the point on their circumference can be drawn, unless the radius is equal to zero as well which then collapses the circles to a point.</li>
@ -19,13 +19,13 @@ Given two points on a plane and a radius, usually two circles of given radius ca
## Instructions
<section id='instructions'>
Implement a function that takes two points and a radius and returns the two circles through those points. For each resulting circle, provide the coordinates for the center of each circle rounded to four decimal digits. Return each coordinate as an array, and coordinates as an array of arrays.
<b>For edge cases, return the following:</b>
<strong>For edge cases, return the following:</strong>
<ul>
<li>If points are on the diameter, return one point. If the radius is also zero however, return <code>"Radius Zero"</code>.</li>
<li>If points are coincident, return <code>"Coincident point. Infinite solutions"</code>.</li>
<li>If points are farther apart than the diameter, return <code>"No intersection. Points further apart than circle diameter"</code>.</li>
</ul>
<b>Sample inputs:</b>
<strong>Sample inputs:</strong>
<pre>
p1 p2 r
0.1234, 0.9876 0.8765, 0.2345 2.0

View File

@ -9,31 +9,31 @@ challengeType: 5
Provide a function to find the closest two points among a set of given points in two dimensions, i.e. to solve the <a href="https://en.wikipedia.org/wiki/Closest pair of points problem" title="wp: Closest pair of points problem" target="blank">Closest pair of points problem</a> in the <i>planar</i> case.
The straightforward solution is a O(n<sup>2</sup>) algorithm (which we can call <i>brute-force algorithm</i>); the pseudo-code (using indexes) could be simply:
<pre>
<b>bruteForceClosestPair</b> of P(1), P(2), ... P(N)
<b>if</b> N < 2 <b>then</b>
<b>return</b>
<b>else</b>
<strong>bruteForceClosestPair</strong> of P(1), P(2), ... P(N)
<strong>if</strong> N < 2 <strong>then</strong>
<strong>return</strong>
<strong>else</strong>
minDistance ← |P(1) - P(2)|
minPoints ← { P(1), P(2) }
<b>foreach</b> i ∈ [1, N-1]
<b>foreach</b> j ∈ [i+1, N]
<b>if</b> |P(i) - P(j)| < minDistance <b>then</b>
<strong>foreach</strong> i ∈ [1, N-1]
<strong>foreach</strong> j ∈ [i+1, N]
<strong>if</strong> |P(i) - P(j)| < minDistance <strong>then</strong>
minDistance ← |P(i) - P(j)|
minPoints ← { P(i), P(j) }
<b>endif</b>
<b>endfor</b>
<b>endfor</b>
<b>return</b> minDistance, minPoints
<b>endif</b>
<strong>endif</strong>
<strong>endfor</strong>
<strong>endfor</strong>
<strong>return</strong> minDistance, minPoints
<strong>endif</strong>
</pre>
A better algorithm is based on the recursive divide and conquer approach, as explained also at <a href="https://en.wikipedia.org/wiki/Closest pair of points problem#Planar_case" title="wp: Closest pair of points problem#Planar_case" target="_blank">Wikipedia's Closest pair of points problem</a>, which is <code>O(nlog(n))</code> a pseudo-code could be:
<pre>
<b>closestPair</b> of (xP, yP)
<strong>closestPair</strong> of (xP, yP)
where xP is P(1) .. P(N) sorted by x coordinate, and
yP is P(1) .. P(N) sorted by y coordinate (ascending order)
<b>if</b> N ≤ 3 <b>then</b>
<b>return</b> closest points of xP using brute-force algorithm
<b>else</b>
<strong>if</strong> N ≤ 3 <strong>then</strong>
<strong>return</strong> closest points of xP using brute-force algorithm
<strong>else</strong>
xL ← points of xP from 1 to ⌈N/2⌉
xR ← points of xP from ⌈N/2⌉+1 to N
xm ← xP(⌈N/2⌉)<sub>x</sub>
@ -42,26 +42,26 @@ A better algorithm is based on the recursive divide and conquer approach, as exp
(dL, pairL) ← closestPair of (xL, yL)
(dR, pairR) ← closestPair of (xR, yR)
(dmin, pairMin) ← (dR, pairR)
<b>if</b> dL < dR <b>then</b>
<strong>if</strong> dL < dR <strong>then</strong>
(dmin, pairMin) ← (dL, pairL)
<b>endif</b>
<strong>endif</strong>
yS ← { p ∈ yP : |xm - p<sub>x</sub>| &lt; dmin }
nS ← number of points in yS
(closest, closestPair) ← (dmin, pairMin)
<b>for</b> i <b>from</b> 1 <b>to</b> nS - 1
<strong>for</strong> i <strong>from</strong> 1 <strong>to</strong> nS - 1
k ← i + 1
<b>while</b> k ≤ nS <b>and</b> yS(k)<sub>y</sub> - yS(i)<sub>y</sub> < dmin
<b>if</b> |yS(k) - yS(i)| < closest <b>then</b>
<strong>while</strong> k ≤ nS <strong>and</strong> yS(k)<sub>y</sub> - yS(i)<sub>y</sub> < dmin
<strong>if</strong> |yS(k) - yS(i)| < closest <strong>then</strong>
(closest, closestPair) ← (|yS(k) - yS(i)|, {yS(k), yS(i)})
<b>endif</b>
<strong>endif</strong>
k ← k + 1
<b>endwhile</b>
<b>endfor</b>
<b>return</b> closest, closestPair
<b>endif</b>
<strong>endwhile</strong>
<strong>endfor</strong>
<strong>return</strong> closest, closestPair
<strong>endif</strong>
</pre>
For the input, expect the argument to be an array of objects (points) with <code>x</code> and <code>y</code> members set to numbers. For the output, return an object containing the key:value pairs for <code>distance</code> and <code>pair</code> (the pair of two closest points).
<b>References and further readings:</b>
<strong>References and further readings:</strong>
<ul>
<li><a href="https://en.wikipedia.org/wiki/Closest pair of points problem" title="wp: Closest pair of points problem" target="_blank">Closest pair of points problem</a></li>
<li><a href="https://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html" target="_blank">Closest Pair (McGill)</a></li>

View File

@ -6,9 +6,9 @@ challengeType: 5
## Description
<section id='description'>
Given non-negative integers <big><b>m</b></big> and <big><b>n</b></big>, generate all size <big><b>m</b></big> combinations of the integers from <big><b>0</b></big> (zero) to <big><b>n-1</b></big> in sorted order (each combination is sorted and the entire table is sorted).
<b>Example:</b>
<big><b>3</b></big> comb <big><b>5</b></big> is:
Given non-negative integers <code>m</code> and <code>n</code>, generate all size <code>m</code> combinations of the integers from <code>0</code> (zero) to <code>n-1</code> in sorted order (each combination is sorted and the entire table is sorted).
<strong>Example:</strong>
<code>3</code> comb <code>5</code> is:
<pre>
0 1 2
0 1 3

View File

@ -13,10 +13,10 @@ Comma quibbling is a task originally set by Eric Lippert in his <a href="https:/
<section id='instructions'>
Write a function to generate a string output which is the concatenation of input words from a list/sequence where:
<ol>
<li>An input of no words produces the output string of just the two brace characters "{}".</li>
<li>An input of just one word, e.g. ["ABC"], produces the output string of the word inside the two braces, e.g. "{ABC}".</li>
<li>An input of two words, e.g. ["ABC", "DEF"], produces the output string of the two words inside the two braces with the words separated by the string " and ", e.g. "{ABC and DEF}".</li>
<li>An input of three or more words, e.g. ["ABC", "DEF", "G", "H"], produces the output string of all but the last word separated by ", " with the last word separated by " and " and all within braces; e.g. "{ABC, DEF, G and H}".</li>
<li>An input of no words produces the output string of just the two brace characters (<code>"{}"</code>)</li>
<li>An input of just one word, e.g. <code>["ABC"]</code>, produces the output string of the word inside the two braces, e.g. <code>"{ABC}"</code></li>
<li>An input of two words, e.g. <code>["ABC", "DEF"]</code>, produces the output string of the two words inside the two braces with the words separated by the string <code>" and "</code>, e.g. <code>"{ABC and DEF}"</code></li>
<li>An input of three or more words, e.g. <code>["ABC", "DEF", "G", "H"]</code>, produces the output string of all but the last word separated by <code>", "</code> with the last word separated by <code>" and "</code> and all within braces; e.g. <code>"{ABC, DEF, G and H}"</code></li>
</ol>
Test your function with the following series of inputs showing your output here on this page:
<ul>

View File

@ -33,7 +33,7 @@ Demonstrate that it passes the following three test-cases:
| second | <code>sec</code> | --- |
</li>
<li>
However, <b>only</b> include quantities with non-zero values in the output (e.g., return <code>1 d</code> and not <code>0 wk, 1 d, 0 hr, 0 min, 0 sec</code>).
However, <strong>only</strong> include quantities with non-zero values in the output (e.g., return <code>1 d</code> and not <code>0 wk, 1 d, 0 hr, 0 min, 0 sec</code>).
</li>
<li>
Give larger units precedence over smaller ones as much as possible (e.g., return <code>2 min, 10 sec</code> and not <code>1 min, 70 sec</code> or <code>130 sec</code>).

View File

@ -8,8 +8,8 @@ challengeType: 5
<section id='description'>
Return an array with the current date in the formats:
<ul>
<li><b>2007-11-23</b> and</li>
<li><b>Sunday, November 23, 2007</b></li>
<li>2007-11-23</li>
<li>Sunday, November 23, 2007</li>
</ul>
Example output: <code>['2007-11-23', 'Sunday, November 23, 2007']</code>
</section>

View File

@ -27,8 +27,8 @@ The algorithm follows:
</ul>
<li>Deal all 52 cards, face up, across 8 columns. The first 8 cards go in 8 columns, the next 8 cards go on the first 8 cards, and so on.</li>
</ol>
<b>Example:</b>
<b>Order to deal cards</b>
<strong>Example:</strong>
<strong>Order to deal cards</strong>
<pre> 1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24
@ -36,7 +36,7 @@ The algorithm follows:
33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48
49 50 51 52</pre>
<b>Game #1</b>
<strong>Game #1</strong>
```js
[
@ -49,7 +49,7 @@ The algorithm follows:
['6S', '9C', '2H', '6H']
]
```
<b>Game #617</b>
<strong>Game #617</strong>
```js
[

View File

@ -7,7 +7,7 @@ challengeType: 5
## Description
<section id='description'>
Implement basic element-wise matrix-matrix and scalar-matrix operations.
<b>Implement:</b>
<strong>Implement:</strong>
<ul>
<li>addition</li>
<li>subtraction</li>

View File

@ -6,19 +6,19 @@ challengeType: 5
## Description
<section id='description'>
An emirp (<b>prime</b> spelled backwards) are primes that when reversed (in their decimal representation) are a different prime.
An emirp (<strong>prime</strong> spelled backwards) are primes that when reversed (in their decimal representation) are a different prime.
</section>
## Instructions
<section id='instructions'>
Write a function that:
<ul>
<li>Shows the first <b>n</b> emirp numbers.</li>
<li>Shows the first <code>n</code> emirp numbers.</li>
<li>Shows the emirp numbers in a range.</li>
<li>Shows the number of emirps in a range.</li>
<li>Shows the <b>n<sup>th</sup></b> emirp number.</li>
<li>Shows the <code>n<sup>th</sup></code> emirp number.</li>
</ul>
The function should accept two parameters. The first will receive <b>n</b> or the range as an array. The second will receive a boolean, that specifies if the function returns the emirps as an array or a single number (the number of primes in the range or the <b>n<sup>th</sup></b> prime). According to the parameters the function should return an array or a number.
The function should accept two parameters. The first will receive <code>n</code> or the range as an array. The second will receive a boolean, that specifies if the function returns the emirps as an array or a single number (the number of primes in the range or the <code>n<sup>th</sup></code> prime). According to the parameters the function should return an array or a number.
</section>
## Tests

View File

@ -17,16 +17,16 @@ For example, in a sequence <big>$A$</big>:
<li><big>$A_5 = 3$</big></li>
<li><big>$A_6 = 0$</big></li>
</ul>
3 is an equilibrium index, because:
<code>3</code> is an equilibrium index, because:
<ul style="list-style: none;">
<li><big>$A_0 + A_1 + A_2 = A_4 + A_5 + A_6$</big></li>
</ul>
6 is also an equilibrium index, because:
<code>6</code> is also an equilibrium index, because:
<ul style="list-style: none;">
<li><big>$A_0 + A_1 + A_2 + A_3 + A_4 + A_5 = 0$</big></li>
</ul>
(sum of zero elements is zero)
7 is not an equilibrium index, because it is not a valid index of sequence <big>$A$</big>.
<code>7</code> is not an equilibrium index, because it is not a valid index of sequence <big>$A$</big>.
</section>
## Instructions

View File

@ -7,15 +7,15 @@ challengeType: 5
## Description
<section id='description'>
Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving.
<b>Method:</b>
<strong>Method:</strong>
<ol>
<li>Take two numbers to be multiplied and write them down at the top of two columns.</li>
<li>In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last in the same column, until you write a value of 1.</li>
<li>In the right-hand column repeatedly double the last number and write the result below. stop when you add a result in the same row as where the left hand column shows 1.</li>
<li>Examine the table produced and discard any row where the value in the left column is even.</li>
<li>Take two numbers to be multiplied and write them down at the top of two columns</li>
<li>In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last in the same column, until you write a value of <code>1</code></li>
<li>In the right-hand column repeatedly double the last number and write the result below. stop when you add a result in the same row as where the left hand column shows <code>1</code></li>
<li>Examine the table produced and discard any row where the value in the left column is even</li>
<li>Sum the values in the right-hand column that remain to produce the result of multiplying the original two numbers together</li>
</ol>
<b>For example:</b> 17 &times; 34
<strong>For example:</strong> <code>17 &times; 34</code>
<pre>
17 34
</pre>
@ -53,7 +53,7 @@ Sum the remaining numbers in the right-hand column:
====
578
</pre>
So 17 multiplied by 34, by the Ethiopian method is 578.
So <code>17</code> multiplied by <code>34</code>, by the Ethiopian method is <code>578</code>.
</section>
## Instructions
@ -62,7 +62,7 @@ The task is to define three named functions/methods/procedures/subroutines:
<ol>
<li>one to halve an integer,</li>
<li>one to double an integer, and</li>
<li>one to state if an integer is even.</li>
<li>one to state if an integer is even</li>
</ol>
Use these functions to create a function that does Ethiopian multiplication.
</section>

View File

@ -32,7 +32,7 @@ The iterative solution rule is then:
<li><big>$y_{n+1} = y_n + h \, f(t_n, y_n)$</big></li>
</ul>
where <big>$h$</big> is the step size, the most relevant parameter for accuracy of the solution. A smaller step size increases accuracy but also the computation cost, so it has always has to be hand-picked according to the problem at hand.
<b>Example: Newton's Cooling Law</b>
<strong>Example: Newton's Cooling Law</strong>
Newton's cooling law describes how an object of initial temperature <big>$T(t_0) = T_0$</big> cools down in an environment of temperature <big>$T_R$</big>:
<ul style="list-style: none;">
<li><big>$\frac{dT(t)}{dt} = -k \, \Delta T$</big></li>
@ -52,17 +52,17 @@ The analytical solution, which we will compare to the numerical approximation, i
<section id='instructions'>
Implement a routine of Euler's method and then to use it to solve the given example of Newton's cooling law with it for three different step sizes of:
<ul>
<li>2 s</li>
<li>5 s and</li>
<li>10 s</li>
<li><code>2 s</code></li>
<li><code>5 s</code> and</li>
<li><code>10 s</code></li>
</ul>
and to compare with the analytical solution.
<b>Initial values:</b>
<strong>Initial values:</strong>
<ul>
<li>initial temperature <big>$T_0$</big> shall be 100 °C</li>
<li>room temperature <big>$T_R$</big> shall be 20 °C</li>
<li>cooling constant <big>$k$</big> shall be 0.07</li>
<li>time interval to calculate shall be from 0s to 100 s</li>
<li>initial temperature <big>$T_0$</big> shall be <code>100 °C</code></li>
<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>
</section>

View File

@ -15,11 +15,11 @@ Rules have the syntax:
[whitespace] ::= ([tab] | [space]) [[whitespace]]
</pre>
There is one rule per line.
If there is a <b>.</b> (period) present before the [replacement], then this is a terminating rule in which case the interpreter must halt execution.
If there is a <code>.</code> (period) present before the [replacement], then this is a terminating rule in which case the interpreter must halt execution.
A ruleset consists of a sequence of rules, with optional comments.
<big><big>Rulesets</big></big>
Use the following tests on entries:
<b>Ruleset 1:</b>
<strong>Ruleset 1:</strong>
<pre>
# This rules file is extracted from Wikipedia:
# http://en.wikipedia.org/wiki/Markov_Algorithm
@ -34,7 +34,7 @@ Sample text of:
<code>I bought a B of As from T S.</code>
Should generate the output:
<code>I bought a bag of apples from my brother.</code>
<b>Ruleset 2:</b>
<strong>Ruleset 2:</strong>
A test of the terminating rule
<pre>
# Slightly modified from the rules on Wikipedia
@ -49,7 +49,7 @@ Sample text of:
<code>I bought a B of As from T S.</code>
Should generate:
<code>I bought a bag of apples from T shop.</code>
<b>Ruleset 3:</b>
<strong>Ruleset 3:</strong>
This tests for correct substitution order and may trap simple regexp based replacement routines if special regexp characters are not escaped.
<pre>
#BNF Syntax testing rules
@ -68,7 +68,7 @@ Sample text of:
<code>I bought a B of As W my Bgage from T S.</code>
Should generate:
<code>I bought a bag of apples with my money from T shop.</code>
<b>Ruleset 4:</b>
<strong>Ruleset 4:</strong>
This tests for correct order of scanning of rules, and may trap replacement routines that scan in the wrong order. It implements a general unary multiplication engine. (Note that the input expression must be placed within underscores in this implementation.)
<pre>
### Unary Multiplication Engine, for testing Markov Algorithm implementations
@ -101,9 +101,9 @@ Sample text of:
<code>_1111*11111_</code>
should generate the output:
<code>11111111111111111111</code>
<b>Ruleset 5:</b>
A simple <a href="http://en.wikipedia.org/wiki/Turing_machine" title="link: http://en.wikipedia.org/wiki/Turing_machine" target="_blank">Turing machine</a>,
implementing a three-state <a href="http://en.wikipedia.org/wiki/Busy_beaver" title="link: http://en.wikipedia.org/wiki/Busy_beaver" target="_blank">busy beaver</a>.The tape consists of <b>0</b>s and <b>1</b>s, the states are <b>A</b>, <b>B</b>, <b>C</b> and <b>H</b> (for <b>H</b>alt), and the head position is indicated by writing the state letter before the character where the head is. All parts of the initial tape the machine operates on have to be given in the input.
<strong>Ruleset 5:</strong>
A simple <a href="http://en.wikipedia.org/wiki/Turing_machine" title="link: http://en.wikipedia.org/wiki/Turing_machine" target="_blank">Turing machine</a>, implementing a three-state <a href="http://en.wikipedia.org/wiki/Busy_beaver" title="link: http://en.wikipedia.org/wiki/Busy_beaver" target="_blank">busy beaver</a>.
The tape consists of <code>0</code>s and <code>1</code>s, the states are <code>A</code>, <code>B</code>, <code>C</code> and <code>H</code> (for <code>H</code>alt), and the head position is indicated by writing the state letter before the character where the head is. All parts of the initial tape the machine operates on have to be given in the input.
Besides demonstrating that the Markov algorithm is Turing-complete, it also made me catch a bug in the C++ implementation which wasn't caught by the first four rulesets.
<pre>
#Turing machine: three-state busy beaver

View File

@ -9,12 +9,12 @@ challengeType: 5
Write a generator of prime numbers, in order, that will automatically adjust to accommodate the generation of any reasonably high prime.
The generator should be able to:
<ul>
<li>Show the first <b>n</b> prime numbers.</li>
<li>Show the prime numbers in a range.</li>
<li>Show the number of primes in a range.</li>
<li>Show the <b>n<sup>th</sup></b> prime number.</li>
<li>Show the first <code>n</code> prime numbers</li>
<li>Show the prime numbers in a range</li>
<li>Show the number of primes in a range</li>
<li>Show the <code>n<sup>th</sup></code> prime number</li>
</ul>
The function should have two parameters. The first will receive <b>n</b> or the range as an array. The second will receive a boolean, that specifies if the function returns the prime numbers as an array or a single number(the number of primes in the range or the <b>n<sup>th</sup></b> prime). According to the parameters the function should return an array.
The function should have two parameters. The first will receive <code>n</code> or the range as an array. The second will receive a boolean, that specifies if the function returns the prime numbers as an array or a single number(the number of primes in the range or the <code>n<sup>th</sup></code> prime). According to the parameters the function should return an array.
</section>
## Instructions

View File

@ -13,11 +13,10 @@ Factorial of a number is given by:
</pre>
For example:
<ul>
<li><big>3! = 3 * 2 * 1 = 6</big></li>
<li><big>4! = 4 * 3 * 2 * 1 = 24</big></li>
<li><code>3! = 3 * 2 * 1 = 6</code></li>
<li><code>4! = 4 * 3 * 2 * 1 = 24</code></li>
</ul>
<b>Note:</b>
0! = 1
<strong>Note:</strong> <code>0! = 1</code>
</section>
## Instructions

View File

@ -6,17 +6,16 @@ challengeType: 5
## Description
<section id='description'>
A Mersenne number is a number in the form of 2<sup>P</sup>-1.
If P is prime, the Mersenne number may be a Mersenne prime
(if P is not prime, the Mersenne number is also not prime).
A Mersenne number is a number in the form of <code>2<sup>P</sup>-1</code>.
If <code>P</code> is prime, the Mersenne number may be a Mersenne prime. (If <code>P</code> 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, <a href="https://rosettacode.org/wiki/Lucas-Lehmer test" title="Lucas-Lehmer test" target="_blank">Lucas-Lehmer test</a>.
There are very efficient algorithms for determining if a number divides 2<sup>P</sup>-1 (or equivalently, if 2<sup>P</sup> mod (the number) = 1).
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>).
Some languages already have built-in implementations of this exponent-and-mod operation (called modPow or similar).
The following is how to implement this modPow yourself:
For example, let's compute 2<sup>23</sup> mod 47.
Convert the exponent 23 to binary, you get 10111. Starting with <tt>square</tt> = 1, repeatedly square it.
Remove the top bit of the exponent, and if it's 1 multiply <tt>square</tt> by the base of the exponentiation (2), then compute <tt>square</tt> modulo 47.
Use the result of the modulo from the last step as the initial value of <tt>square</tt> in the next step:
For example, let's compute <code>2<sup>23</sup> mod 47</code>.
Convert the exponent 23 to binary, you get 10111. Starting with <code><tt>square</tt> = 1</code>, repeatedly square it.
Remove the top bit of the exponent, and if it's 1 multiply <code><tt>square</tt></code> by the base of the exponentiation (2), then compute <code><tt>square</tt> modulo 47</code>.
Use the result of the modulo from the last step as the initial value of <code><tt>square</tt></code> in the next step:
<pre>
Remove Optional
square top bit multiply by 2 mod 47
@ -27,18 +26,18 @@ square top bit multiply by 2 mod 47
32*32 = 1024 1 1 1024*2 = 2048 27
27*27 = 729 1 729*2 = 1458 1
</pre>
Since 2<sup>23</sup> mod 47 = 1, 47 is a factor of 2<sup>P</sup>-1.
(To see this, subtract 1 from both sides: 2<sup>23</sup>-1 = 0 mod 47.)
Since we've shown that 47 is a factor, 2<sup>23</sup>-1 is not prime.
Since <code>2<sup>23</sup> mod 47 = 1</code>, 47 is a factor of <code>2<sup>P</sup>-1</code>.
(To see this, subtract 1 from both sides: <code>2<sup>23</sup>-1 = 0 mod 47</code>.)
Since we've shown that 47 is a factor, <code>2<sup>23</sup>-1</code> is not prime.
Further properties of Mersenne numbers allow us to refine the process even more.
Any factor q of 2<sup>P</sup>-1 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 <a href="https://rosettacode.org/wiki/Primality by Trial Division" title="Primality by Trial Division" target="_blank">prime</a>.
As in other trial division algorithms, the algorithm stops when 2kP+1 > sqrt(N).These primality tests only work on Mersenne numbers where P is prime. For example, M<sub>4</sub>=15 yields no factors using these techniques, but factors into 3 and 5, neither of which fit 2kP+1.
Any factor <code>q</code> of <code>2<sup>P</sup>-1</code> must be of the form <code>2kP+1</code>, <code>k</code> being a positive integer or zero. Furthermore, <code>q</code> must be <code>1</code> or <code>7 mod 8</code>.
Finally any potential factor <code>q</code> must be <a href="https://rosettacode.org/wiki/Primality by Trial Division" title="Primality by Trial Division" target="_blank">prime</a>.
As in other trial division algorithms, the algorithm stops when <code>2kP+1 > sqrt(N)</code>.These primarily tests only work on Mersenne numbers where <code>P</code> 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 <code>2kP+1</code>.
</section>
## Instructions
<section id='instructions'>
Using the above method find a factor of 2<sup>929</sup>-1 (aka M929)
Using the above method find a factor of <code>2<sup>929</sup>-1</code> (aka M929)
</section>
## Tests

View File

@ -6,14 +6,14 @@ challengeType: 5
## Description
<section id='description'>
The <a href="https://en.wikipedia.org/wiki/Farey sequence" title="wp: Farey sequence" target="_blank">Farey sequence</a> <b>F<sub>n</sub></b> of order <b>n</b> is the sequence of completely reduced fractions between <b>0</b> and <b>1</b> which, when in lowest terms, have denominators less than or equal to <b>n</b>, arranged in order of increasing size.
The <a href="https://en.wikipedia.org/wiki/Farey sequence" title="wp: Farey sequence" target="_blank">Farey sequence</a> <code>F<sub>n</sub></code> of order <code>n</code> is the sequence of completely reduced fractions between <code>0</code> and <code>1</code> which, when in lowest terms, have denominators less than or equal to <code>n</code>, arranged in order of increasing size.
The <i>Farey sequence</i> is sometimes incorrectly called a <i>Farey series</i>.
Each Farey sequence:
<ul>
<li>starts with the value 0, denoted by the fraction $ \frac{0}{1} $</li>
<li>ends with the value 1, denoted by the fraction $ \frac{1}{1}$.</li>
</ul>
The Farey sequences of orders <b>1</b> to <b>5</b> are:
The Farey sequences of orders <code>1</code> to <code>5</code> are:
<ul>
<li style="list-style: none;">${\bf\it{F}}_1 = \frac{0}{1}, \frac{1}{1}$</li>
<li style="list-style: none;">${\bf\it{F}}_2 = \frac{0}{1}, \frac{1}{2}, \frac{1}{1}$</li>
@ -25,7 +25,7 @@ The Farey sequences of orders <b>1</b> to <b>5</b> are:
## Instructions
<section id='instructions'>
Write a function that returns the Farey sequence of order <b>n</b>. The function should have one parameter that is <b>n</b>. It should return the sequence as an array.
Write a function that returns the Farey sequence of order <code>n</code>. The function should have one parameter that is <code>n</code>. It should return the sequence as an array.
</section>
## Tests

View File

@ -33,7 +33,7 @@ The <a href="https://en.wikipedia.org/wiki/Lucas number" title="wp: Lucas number
## Instructions
<section id='instructions'>
Write a function to generate Fibonacci n-step number sequences and Lucas sequences. The first parameter will be n. The second parameter will be the number of elements to be returned. The third parameter will specify whether to output the Fibonacci sequence or the Lucas sequence. If the parameter is "f" then return the Fibonacci sequence and if it is "l", then return the Lucas sequence. The sequences must be returned as an array.
Write a function to generate Fibonacci $n$-step number sequences and Lucas sequences. The first parameter will be $n$. The second parameter will be the number of elements to be returned. The third parameter will specify whether to output the Fibonacci sequence or the Lucas sequence. If the parameter is <code>"f"</code> then return the Fibonacci sequence and if it is <code>"l"</code>, then return the Lucas sequence. The sequences must be returned as an array.
</section>
## Tests

View File

@ -6,10 +6,10 @@ challengeType: 5
## Description
<section id='description'>
Write a function to generate the <big>n<sup>th</sup></big> Fibonacci number.
The <big>n<sup>th</sup></big> Fibonacci number is given by:
F<sub>n</sub> = F<sub>n-1</sub> + F<sub>n-2</sub>
The first two terms of the series are 0, 1.
Write a function to generate the <code>n<sup>th</sup></code> Fibonacci number.
The <code>n<sup>th</sup></code> Fibonacci number is given by:
<code>F<sub>n</sub> = F<sub>n-1</sub> + F<sub>n-2</sub></code>
The first two terms of the series are 0 and 1.
Hence, the series is: 0, 1, 1, 2, 3, 5, 8, 13...
</section>

View File

@ -8,16 +8,16 @@ challengeType: 5
<section id='description'>
The Fibonacci Word may be created in a manner analogous to the Fibonacci Sequence <a href="https://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf" target="_blank">as described here</a>:
<pre>
Define F_Word<sub>1</sub> as <b>1</b>
Define F_Word<sub>2</sub> as <b>0</b>
Form F_Word<sub>3</sub> as F_Word<sub>2</sub> concatenated with F_Word<sub>1</sub> i.e.: <b>01</b>
Define F_Word<sub>1</sub> as <strong>1</strong>
Define F_Word<sub>2</sub> as <strong>0</strong>
Form F_Word<sub>3</sub> as F_Word<sub>2</sub> concatenated with F_Word<sub>1</sub> i.e.: <strong>01</strong>
Form F_Word<sub>n</sub> as F_Word<sub>n-1</sub> concatenated with F_word<sub>n-2</sub>
</pre>
</section>
## Instructions
<section id='instructions'>
Write a function to return the Fibonacci Words upto <b>N</b>. <b>N</b> will be provided as a parameter to the function. The function should return an array of objects. The objects should be of the form: <code>{ N: 1, Length: 1, Entropy: 0, Word: '1' }</code>.
Write a function to return the Fibonacci Words up to <code>n</code>. <code>n</code> will be provided as a parameter to the function. The function should return an array of objects. The objects should be of the form: <code>{ N: 1, Length: 1, Entropy: 0, Word: '1' }</code>.
</section>
## Tests
@ -26,11 +26,11 @@ Write a function to return the Fibonacci Words upto <b>N</b>. <b>N</b> will be p
```yml
tests:
- text: <code>fibWord</code> is a function.
testString: assert(typeof fibWord === 'function', '<code>fibWord</code> is a function.');
testString: assert(typeof fibWord === 'function');
- text: <code>fibWord(5)</code> should return an array.
testString: assert(Array.isArray(fibWord(5)),'<code>fibWord(5)</code> should return an array.');
- text: <code>fibWord(5)</code> should return <code>'+JSON.stringify(ans)+'</code>.
testString: assert.deepEqual(fibWord(5),ans,'<code>fibWord(5)</code> should return <code>'+JSON.stringify(ans)+'</code>.');
testString: assert(Array.isArray(fibWord(5)));
- text: <code>fibWord(5)</code> should return <code>[{ N:1, Length:1, Entropy:0, Word:"1" },{ N:2, Length:1, Entropy:0, Word:"0" },{ N:3, Length:2, Entropy:1, Word:"01" },{ N:4, Length:3, Entropy:0.9182958340544896, Word:"010" },{ N:5, Length:5, Entropy:0.9709505944546688, Word:"01001" }]</code>.
testString: assert.deepEqual(fibWord(5),ans);
```

View File

@ -6,11 +6,11 @@ challengeType: 5
## Description
<section id='description'>
The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
The Hailstone sequence of numbers can be generated from a starting positive integer, <code>n</code> by:
<ul>
<li>If n is <b>1</b> then the sequence ends.</li>
<li>If n is <b>even</b> then the next n of the sequence <code>= n/2</code></li>
<li>If n is <b>odd</b> then the next n of the sequence <code>= (3 * n) + 1</code></li>
<li>If <code>n</code> is <code>1</code> then the sequence ends</li>
<li>If <code>n</code> is <code>even</code> then the next <code>n</code> of the sequence <code>= n/2</code></li>
<li>If <code>n</code> is <code>odd</code> then the next <code>n</code> of the sequence <code>= (3 * n) + 1</code></li>
</ul>
The (unproven) <a href="https://en.wikipedia.org/wiki/Collatz conjecture" title="wp: Collatz conjecture" target="_blank">Collatz conjecture</a> is that the hailstone sequence for any starting number always terminates.
The hailstone sequence is also known as hailstone numbers (because the values are usually subject to multiple descents and ascents like hailstones in a cloud), or as the Collatz sequence.
@ -19,11 +19,11 @@ The hailstone sequence is also known as hailstone numbers (because the values ar
## Instructions
<section id='instructions'>
<ol>
<li>Create a routine to generate the hailstone sequence for a number.</li>
<li>Create a routine to generate the hailstone sequence for a number</li>
<li>Use the routine to show that the hailstone sequence for the number 27 has 112 elements starting with <code>27, 82, 41, 124</code> and ending with <code>8, 4, 2, 1</code></li>
<li>Show the number less than 100,000 which has the longest hailstone sequence together with that sequence's length. (But don't show the actual sequence!)</li>
</ol>
<b>See also:</b>
<strong>See also:</strong>
<ul>
<li><a href="https://xkcd.com/710" target="_blank">xkcd</a> (humourous).</li>
</ul>

View File

@ -7,7 +7,7 @@ challengeType: 5
## Description
<section id='description'>
A <a href="https://en.wikipedia.org/wiki/Happy_number" target="_blank">happy number</a> is defined by the following process:
Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals <b>1</b> (where it will stay), or it loops endlessly in a cycle which does not include <b>1</b>. Those numbers for which this process ends in <b>1</b> are happy numbers, while those that do not end in <b>1</b> are unhappy numbers.
Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals <code>1</code> (where it will stay), or it loops endlessly in a cycle which does not include <code>1</code>. Those numbers for which this process ends in <code>1</code> are happy numbers, while those that do not end in <code>1</code> are unhappy numbers.
</section>
## Instructions

View File

@ -7,7 +7,7 @@ challengeType: 5
## Description
<section id='description'>
The Harshad or Niven numbers are positive integers ≥ 1 that are divisible by the sum of their digits.
For example, <b>42</b> is a <a href="https://rosettacode.org/wiki/Harshad_or_Niven_series" title="Harshad or Niven series" target="_blank">Harshad number</a> as <b>42</b> is divisible by <b>(4 + 2)</b> without remainder.
For example, <code>42</code> is a <a href="https://rosettacode.org/wiki/Harshad_or_Niven_series" title="Harshad or Niven series" target="_blank">Harshad number</a> as <code>42</code> is divisible by <code>(4 + 2)</code> without remainder.
Assume that the series is defined as the numbers in increasing order.
</section>

View File

@ -7,7 +7,7 @@ challengeType: 5
## Description
<section id='description'>
Using two Arrays of equal length, create a Hash object where the elements from one array (the keys) are linked to the elements of the other (the values).
<b>Related task:</b>
<strong>Related task:</strong>
<ul>
<li><a href="https://rosettacode.org/wiki/Associative arrays/Creation" title="Associative arrays/Creation" target="_blank">Associative arrays/Creation</a></li>
</ul>

View File

@ -9,34 +9,34 @@ challengeType: 5
An <a href="https://en.wikipedia.org/wiki/Join_(SQL)#Inner_join" title="wp: Join_(SQL)#Inner_join" target="_blank">inner join</a> 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 <a href="https://en.wikipedia.org/wiki/Nested loop join" title="wp: Nested loop join" target="_blank">nested loop join</a> algorithm, but a more scalable alternative is the <a href="https://en.wikipedia.org/wiki/hash join" title="wp: hash join" target="_blank">hash join</a> algorithm.
The "hash join" algorithm consists of two steps:
<ol>
<li><b>Hash phase:</b> Create a <a href="https://en.wikipedia.org/wiki/Multimap" title="wp: Multimap" target="_blank">multimap</a> from one of the two tables, mapping from each join column value to all the rows that contain it.</li>
<li><strong>Hash phase:</strong> Create a <a href="https://en.wikipedia.org/wiki/Multimap" title="wp: Multimap" target="_blank">multimap</a> from one of the two tables, mapping from each join column value to all the rows that contain it.</li>
<ul>
<li>The multimap must support hash-based lookup which scales better than a simple linear search, because that's the whole point of this algorithm.</li>
<li>Ideally we should create the multimap for the smaller table, thus minimizing its creation time and memory size.</li>
</ul>
<li><b>Join phase:</b> Scan the other table, and find matching rows by looking in the multimap created before.</li>
<li><strong>Join phase:</strong> Scan the other table, and find matching rows by looking in the multimap created before.</li>
</ol>
In pseudo-code, the algorithm could be expressed as follows:
<pre>
<b>let</b> <i>A</i> = the first input table (or ideally, the larger one)
<b>let</b> <i>B</i> = the second input table (or ideally, the smaller one)
<b>let</b> <i>j<sub>A</sub></i> = the join column ID of table <i>A</i>
<b>let</b> <i>j<sub>B</sub></i> = the join column ID of table <i>B</i>
<b>let</b> <i>M<sub>B</sub></i> = a multimap for mapping from single values to multiple rows of table <i>B</i> (starts out empty)
<b>let</b> <i>C</i> = the output table (starts out empty)
<b>for each</b> row <i>b</i> in table <i>B</i>:
<b>place</b> <i>b</i> in multimap <i>M<sub>B</sub></i> under key <i>b(j<sub>B</sub>)</i>
<b>for each</b> row <i>a</i> in table <i>A</i>:
<b>for each</b> row <i>b</i> in multimap <i>M<sub>B</sub></i> under key <i>a(j<sub>A</sub>)</i>:
<b>let</b> <i>c</i> = the concatenation of row <i>a</i> and row <i>b</i>
<b>place</b> row <i>c</i> in table <i>C</i>
<strong>let</strong> <i>A</i> = the first input table (or ideally, the larger one)
<strong>let</strong> <i>B</i> = the second input table (or ideally, the smaller one)
<strong>let</strong> <i>j<sub>A</sub></i> = the join column ID of table <i>A</i>
<strong>let</strong> <i>j<sub>B</sub></i> = the join column ID of table <i>B</i>
<strong>let</strong> <i>M<sub>B</sub></i> = a multimap for mapping from single values to multiple rows of table <i>B</i> (starts out empty)
<strong>let</strong> <i>C</i> = the output table (starts out empty)
<strong>for each</strong> row <i>b</i> in table <i>B</i>:
<strong>place</strong> <i>b</i> in multimap <i>M<sub>B</sub></i> under key <i>b(j<sub>B</sub>)</i>
<strong>for each</strong> row <i>a</i> in table <i>A</i>:
<strong>for each</strong> row <i>b</i> in multimap <i>M<sub>B</sub></i> under key <i>a(j<sub>A</sub>)</i>:
<strong>let</strong> <i>c</i> = the concatenation of row <i>a</i> and row <i>b</i>
<strong>place</strong> row <i>c</i> in table <i>C</i>
</pre>
</section>
## Instructions
<section id='instructions'>
Implement the "hash join" algorithm as a function and demonstrate that it passes the test-case listed below. The function should accept two arrays of objects and return an array of combined objects.
<h4><b>Input</b></h4>
<h4><strong>Input</strong></h4>
<table>
<tr>
<td style="padding: 4px; margin: 5px;">
@ -114,7 +114,7 @@ Implement the "hash join" algorithm as a function and demonstrate that it passes
</td>
<td style="padding: 4px; margin: 5px;">
</td></tr></table>
<h4><b>Output</b></h4>
<h4><strong>Output</strong></h4>
<table>
<tr>
<th style="padding: 4px; margin: 5px;"> A_age </th>

View File

@ -11,11 +11,11 @@ challengeType: 5
where <big>s</big> is half the perimeter of the triangle; that is,
<span style="margin-left: 2em;"><big>$s=\frac{a+b+c}{2}.$</big></span>
Heronian triangles are triangles whose sides and area are all integers.
An example is the triangle with sides <b>3, 4, 5</b> whose area is <b>6</b> (and whose perimeter is <b>12</b>).
Note that any triangle whose sides are all an integer multiple of <b>3, 4, 5</b>; such as <b>6, 8, 10,</b> will also be a Heronian triangle.
An example is the triangle with sides <code>3, 4, 5</code> whose area is <code>6</code> (and whose perimeter is <code>12</code>).
Note that any triangle whose sides are all an integer multiple of <code>3, 4, 5</code>; such as <code>6, 8, 10,</code> will also be a Heronian triangle.
Define a Primitive Heronian triangle as a Heronian triangle where the greatest common divisor
of all three sides is <b>1</b> (unity).
This will exclude, for example, triangle <b>6, 8, 10.</b>
of all three sides is <code>1</code> (unity).
This will exclude, for example, triangle <code>6, 8, 10.</code>
</section>
## Instructions

View File

@ -17,9 +17,9 @@ Sequence <big>$S$</big> starts:
## Instructions
<section id='instructions'>
Create two functions named <b>ffr</b> and <b>ffs</b> that when given <b>n</b> return <b>R(n)</b> or <b>S(n)</b> respectively. (Note that R(1) = 1 and S(1) = 2 to avoid off-by-one errors).
No maximum value for <b>n</b> should be assumed.
<b>References</b>
Create two functions named <code>ffr</code> and <code>ffs</code> that when given <code>n</code> return <code>R(n)</code> or <code>S(n)</code> respectively. (Note that R(1) = 1 and S(1) = 2 to avoid off-by-one errors).
No maximum value for <code>n</code> should be assumed.
<strong>References</strong>
<ul>
<li>
Sloane's <a href="https://oeis.org/A005228" target="_blank">A005228</a> and <a href="https://oeis.org/A030124" target="_blank">A030124</a>.

View File

@ -6,7 +6,7 @@ challengeType: 5
## Description
<section id='description'>
An <i>identity matrix</i> is a square matrix of size \( n \times n \), where the diagonal elements are all <b>1</b>s (ones), and all the other elements are all <b>0</b>s (zeroes).
An <i>identity matrix</i> is a square matrix of size \( n \times n \), where the diagonal elements are all <code>1</code>s (ones), and all the other elements are all <code>0</code>s (zeroes).
<ul>
<li style="list-style: none;">\(\displaystyle I_{n}=\begin{bmatrix} 1 & 0 & 0 \cr 0 & 1 & 0 \cr 0 & 0 & 1 \cr \end{bmatrix}\)</li>
</ul>

View File

@ -6,8 +6,8 @@ challengeType: 5
## Description
<section id='description'>
The Jaro distance is a measure of similarity between two strings. The higher the Jaro distance for two strings is, the more similar the strings are. The score is normalized such that <b>0</b> equates to no similarity and <b>1</b> is an exact match.
<b>Definition</b>
The Jaro distance is a measure of similarity between two strings. The higher the Jaro distance for two strings is, the more similar the strings are. The score is normalized such that <code>0</code> equates to no similarity and <code>1</code> is an exact match.
<strong>Definition</strong>
The Jaro distance \( d_j \) of two given strings \(s_1\) and \(s_2\) is
\begin{align}d_j = \begin{cases}0&amp; & \text{if }m=0 \\\\{\frac {1}{3}}\left({\frac {m}{|s_{1}|}}+{\frac {m}{|s_{2}|}}+{\frac {m-t}{m}}\right)&amp; & \text{otherwise}\end{cases}\end{align}
Where:
@ -17,7 +17,7 @@ Where:
</uL>
Two characters from \(s_1\) and \(s_2\) respectively, are considered <i>matching</i> only if they are the same and not farther than \(\left\lfloor\frac{\max(|s_1|,|s_2|)}{2}\right\rfloor-1\).
Each character of \(s_1\) is compared with all its matching characters in \(s_2\) . The number of matching (but different sequence order) characters divided by 2 defines the number of <i>transpositions</i>.
<b>Example</b>
<strong>Example</strong>
Given the strings \(s_1\) <i>DWAYNE</i> and \(s_2\) <i>DUANE</i> we find:
<ul>
<li>\(m = 4\)</li>

View File

@ -16,14 +16,14 @@ The function should read a single but nested S-Expression from a string and retu
Newlines and other whitespace may be ignored unless contained within a quoted string.
"<tt>()</tt>" inside quoted strings are not interpreted, but treated as part of the string.
Handling escaped quotes inside a string is optional; thus "<tt>(foo"bar)</tt>" may be treated as a string "<tt>foo"bar</tt>", or as an error.
For this, the reader need not recognize "<tt>\</tt>" for escaping, but should, in addition, recognize numbers if the language has appropriate datatypes.
For this, the reader need not recognize "<tt>\</tt>" for escaping, but should, in addition, recognize numbers if the language has appropriate data types.
Note that with the exception of "<tt>()"</tt>" ("<tt>\</tt>" if escaping is supported) and whitespace there are no special characters. Anything else is allowed without quotes.
The reader should be able to read the following input
<pre>
((data "quoted data" 123 4.5)
(data (!@# (4.5) "(more" "data)")))
</pre>
and turn it into a native datastructure. (see the <a href="https://rosettacode.org/wiki/S-Expressions#Pike" title="#Pike" target="_blank">Pike</a>, <a href="https://rosettacode.org/wiki/S-Expressions#Python" title="#Python" target="_blank">Python</a> and <a href="https://rosettacode.org/wiki/S-Expressions#Ruby" title="#Ruby" target="_blank">Ruby</a> implementations for examples of native data structures.)
and turn it into a native data structure. (See the <a href="https://rosettacode.org/wiki/S-Expressions#Pike" title="#Pike" target="_blank">Pike</a>, <a href="https://rosettacode.org/wiki/S-Expressions#Python" title="#Python" target="_blank">Python</a> and <a href="https://rosettacode.org/wiki/S-Expressions#Ruby" title="#Ruby" target="_blank">Ruby</a> implementations for examples of native data structures.)
</section>
## Tests

View File

@ -15,9 +15,9 @@ In the morning (after the surreptitious and separate action of each of the five
## Instructions
<section id='instructions'>
Create a function that returns the minimum possible size of the initial pile of coconuts collected during the day for <code>N</code> sailors.
<b>Note:</b>
<strong>Note:</strong>
Of course the tale is told in a world where the collection of any amount of coconuts in a day and multiple divisions of the pile, etc. can occur in time fitting the story line, so as not to affect the mathematics.
<b>C.f:</b>
<strong>C.f:</strong>
<ul>
<li><a href="https://www.youtube.com/watch?v=U9qU20VmvaU" target="_blank"> Monkeys and Coconuts - Numberphile</a> (Video) Analytical solution.</li>
<li><a href="https://oeis.org/A002021" target="_blank">A002021 Pile of coconuts problem</a> The On-Line Encyclopedia of Integer Sequences. (Although some of its references may use the alternate form of the tale).</li>

View File

@ -7,7 +7,7 @@ challengeType: 5
## Description
<section id='description'>
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:
The first taxicab number is <code>1729</code>, 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:
@ -22,7 +22,7 @@ Taxicab numbers are also known as:
## 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>
<strong>See also:</strong>
<ul>
<li><a href="https://oeis.org/A001235" target="_blank">A001235 taxicab numbers</a> on The On-Line Encyclopedia of Integer Sequences.</li>
<li><a href="https://en.wikipedia.org/wiki/Taxicab_number" target="_blank">taxicab number</a> on Wikipedia.</li>

View File

@ -9,9 +9,9 @@ challengeType: 5
Write a function or program that can split a string at each non-escaped occurrence of a separator character.
It should accept three input parameters:
<ul>
<li>The <b>string</b></li>
<li>The <b>separator character</b></li>
<li>The <b>escape character</b></li>
<li>The <strong>string</strong></li>
<li>The <strong>separator character</strong></li>
<li>The <strong>escape character</strong></li>
</ul>
It should output a list of strings.
Rules for splitting:

View File

@ -38,7 +38,7 @@ std_cell_lib ieee std_cell_lib
synopsys
</pre>
<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>
<b>C.f.:</b>
<strong>C.f.:</strong>
<ul>
<li><a href="https://rosettacode.org/wiki/Topological sort/Extracted top item" title="Topological sort/Extracted top item" target="_blank">Topological sort/Extracted top item</a>.</li>
</ul>

View File

@ -16,7 +16,7 @@ Write a function that can wrap this text to any number of characters. As an exam
Wrap text using a more sophisticated algorithm such as the Knuth and Plass TeX
algorithm. If your language provides this, you get easy extra credit, but you
must reference documentation indicating that the algorithm is something better
than a simple minimimum length algorithm.
than a simple minimum length algorithm.
</pre>
</section>

View File

@ -13,7 +13,7 @@ The <a href="https://mvanier.livejournal.com/2897.html" target="_blank">Y combin
## Instructions
<section id='instructions'>
Define the stateless Y combinator function and use it to compute <a href="https://en.wikipedia.org/wiki/Factorial" title="wp: factorial" target="_blank">factorial</a>. The <code>factorial(N)</code> function is already given to you.
<b>See also:</b>
<strong>See also:</strong>
<ul>
<li><a href="https://vimeo.com/45140590" target="_blank">Jim Weirich: Adventures in Functional Programming</a>.</li>
</ul>

View File

@ -52,7 +52,7 @@ The algorithm operates on all black pixels P1 that can have eight neighbours. Th
<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;"><b>P1</b></td><td style="text-align: center;">P4</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>
@ -68,8 +68,8 @@ All pixels are tested and pixels satisfying all the following conditions (simult
<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 <b>P2, P4 and P6</b> is white</li>
<li>At least one of <b>P4, P6 and P8</b> is white</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>
After iterating over the image and collecting all the pixels satisfying all step 1 conditions, all these condition satisfying pixels are set to white.
@ -79,8 +79,8 @@ All pixels are again tested and pixels satisfying all the following conditions a
<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 <b>P2, P4 and P8</b> is white</li>
<li>At least one of <b>P2, P6 and P8</b> is white</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>
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.
<h3>Iteration:</h3>