Fixing other problems from comments
This commit is contained in:
@ -26,7 +26,7 @@ This can be visualized in the following form:
|
||||
1 3 3 2 1 1
|
||||
</pre>
|
||||
Where row $n$ corresponds to integer $n$, and each column $C$ in row $m$ from left to right corresponds to the number of names beginning with $C$.
|
||||
Optionally note that the sum of the $n$-th row $P(n)$ is the <a href="https://mathworld.wolfram.com/PartitionFunctionP.html" title="link: https://mathworld.wolfram.com/PartitionFunctionP.html">integer partition function</a>.
|
||||
Optionally note that the sum of the $n$-th row $P(n)$ is the integer partition function.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -6,7 +6,7 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
A problem posed by <a href='https://en.wikipedia.org/wiki/Paul_Graham' target='_blank'>Paul Graham</a> is that of creating a function that takes a single (numeric) argument and which returns another function that is an accumulator. The returned accumulator function in turn also takes a single numeric argument, and returns the sum of all the numeric values passed in so far to that accumulator (including the initial value passed when the accumulator was created).
|
||||
A problem posed by <a href='https://en.wikipedia.org/wiki/Paul_Graham_(programmer)' target='_blank'>Paul Graham</a> is that of creating a function that takes a single (numeric) argument and which returns another function that is an accumulator. The returned accumulator function in turn also takes a single numeric argument, and returns the sum of all the numeric values passed in so far to that accumulator (including the initial value passed when the accumulator was created).
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -24,15 +24,15 @@ Further,$allow$for$each$word$in$a$column$to$be$either$left$
|
||||
justified,$right$justified
|
||||
or$center$justified$within$its$column.
|
||||
</pre>
|
||||
Note that:
|
||||
<ol>
|
||||
<strong>Note that:</strong>
|
||||
<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>
|
||||
</ol>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
|
@ -6,9 +6,9 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Two integers $N$ and $M$ are said to be <a href='https://en.wikipedia.org/wiki/Amicable numbers' title='wp: Amicable numbers' target='_blank'>amicable pairs</a> if $N \neq M$ and the sum of the <a href="https://rosettacode.org/wiki/Proper divisors" title="Proper divisors">proper divisors</a> of $N$ ($\mathrm{sum}(\mathrm{propDivs}(N))$) $= M$ as well as $\mathrm{sum}(\mathrm{propDivs}(M)) = N$.
|
||||
<b>Example:</b>
|
||||
<b>1184</b> and <b>1210</b> are an amicable pair, with proper divisors:
|
||||
Two integers $N$ and $M$ are said to be <a href='https://en.wikipedia.org/wiki/Amicable numbers' title='wp: Amicable numbers' target='_blank'>amicable pairs</a> if $N \neq M$ and the sum of the <a href="https://rosettacode.org/wiki/Proper divisors" title="Proper divisors" target="_blank">proper divisors</a> of $N$ ($\mathrm{sum}(\mathrm{propDivs}(N))$) $= M$ as well as $\mathrm{sum}(\mathrm{propDivs}(M)) = N$.
|
||||
<strong>Example:</strong>
|
||||
<strong>1184</strong> and <strong>1210</strong> are an amicable pair, with proper divisors:
|
||||
<ul>
|
||||
<li>1, 2, 4, 8, 16, 32, 37, 74, 148, 296, 592 and</li>
|
||||
<li>1, 2, 5, 10, 11, 22, 55, 110, 121, 242, 605 respectively.</li>
|
||||
|
@ -6,7 +6,7 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Compute all three of the <a class='rosetta__link--wiki' href='https://en.wikipedia.org/wiki/Pythagorean means' title='wp: Pythagorean means'>Pythagorean means</a> of the set of integers <big>1</big> through <big>10</big> (inclusive).
|
||||
Compute all three of the <a class='rosetta__link--wiki' href='https://en.wikipedia.org/wiki/Pythagorean means' title='wp: Pythagorean means' target="_blank">Pythagorean means</a> of the set of integers <big>1</big> through <big>10</big> (inclusive).
|
||||
Show that <big>$A(x_1,\ldots,x_n) \geq G(x_1,\ldots,x_n) \geq H(x_1,\ldots,x_n)$</big> for this set of positive integers.
|
||||
<ul>
|
||||
<li>The most common of the three means, the <a class='rosetta__link--rosetta' href='https://rosettacode.org/wiki/Averages/Arithmetic mean' title='Averages/Arithmetic mean' target='_blank'>arithmetic mean</a>, is the sum of the list divided by its length:<br>
|
||||
@ -22,7 +22,8 @@ Show that <big>$A(x_1,\ldots,x_n) \geq G(x_1,\ldots,x_n) \geq H(x_1,\ldots,x_n)$
|
||||
<section id='instructions'>
|
||||
When writing your function, assume the input is an ordered array of all inclusive numbers.
|
||||
For the answer, please output an object in the following format:
|
||||
<pre>
|
||||
|
||||
```js
|
||||
{
|
||||
values: {
|
||||
Arithmetic: 5.5,
|
||||
@ -31,7 +32,8 @@ For the answer, please output an object in the following format:
|
||||
},
|
||||
test: 'is A >= G >= H ? yes'
|
||||
}
|
||||
</pre>
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
|
@ -34,8 +34,6 @@ Implement a function that takes two points and a radius and returns the two circ
|
||||
0.1234, 0.9876 0.8765, 0.2345 0.5
|
||||
0.1234, 0.9876 0.1234, 0.9876 0.0
|
||||
</pre>
|
||||
<b>Ref:</b>
|
||||
<a href="https://mathforum.org/library/drmath/view/53027.html" target="_blank">Finding the Center of a Circle from 2 Points and Radius</a> from Math forum @ Drexel
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
|
@ -6,7 +6,7 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
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">Closest pair of points problem</a> in the <i>planar</i> case.
|
||||
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)
|
||||
@ -26,7 +26,7 @@ The straightforward solution is a O(n<sup>2</sup>) algorithm (which we can call
|
||||
<b>return</b> minDistance, minPoints
|
||||
<b>endif</b>
|
||||
</pre>
|
||||
A better algorithm is based on the recursive divide & 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">Wikipedia's Closest pair of points problem</a>, which is O(<i>n</i> log <i>n</i>); a pseudo-code could be:
|
||||
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)
|
||||
where xP is P(1) .. P(N) sorted by x coordinate, and
|
||||
@ -63,11 +63,10 @@ A better algorithm is based on the recursive divide & conquer approach, as expla
|
||||
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>
|
||||
<ul>
|
||||
<li><a href="https://en.wikipedia.org/wiki/Closest pair of points problem" title="wp: Closest pair of points problem">Closest pair of points problem</a></li>
|
||||
<li><a href="https://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html">Closest Pair (McGill)</a></li>
|
||||
<li><a href="https://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf">Closest Pair (UCSB)</a></li>
|
||||
<li><a href="https://classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf">Closest pair (WUStL)</a></li>
|
||||
<li><a href="https://www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt">Closest pair (IUPUI)</a></li>
|
||||
<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>
|
||||
<li><a href="https://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf" target="_blank">Closest Pair (UCSB)</a></li>
|
||||
<li><a href="https://classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf" target="_blank">Closest pair (WUStL)</a></li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
|
@ -6,7 +6,7 @@ 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><a href="https://mathworld.wolfram.com/Combination.html"> combinations</a> 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).
|
||||
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:
|
||||
<pre>
|
||||
|
@ -25,7 +25,7 @@ Test your function with the following series of inputs showing your output here
|
||||
<li>["ABC", "DEF"]</li>
|
||||
<li>["ABC", "DEF", "G", "H"]</li>
|
||||
</ul>
|
||||
Note: Assume words are non-empty strings of uppercase characters for this task.
|
||||
<strong>Note:</strong> Assume words are non-empty strings of uppercase characters for this task.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
|
@ -27,10 +27,6 @@ There are four types of common coins in <a href="https://en.wikipedia.org/wiki/U
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Implement a function to determine how many ways there are to make change for a dollar using these common coins (1 dollar = 100 cents)
|
||||
<b>Reference:</b>
|
||||
<ul>
|
||||
<li><a href="https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_Temp_52" target="_blank">an algorithm from MIT Press</a>.</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
|
@ -6,7 +6,7 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
In <a href="https://en.wikipedia.org/wiki/linear algebra" title="wp: linear algebra">linear algebra</a>, <a href="https://en.wikipedia.org/wiki/Cramer's rule" title="wp: Cramer's rule">Cramer's rule</a> is an explicit formula for the solution of a <a href="https://en.wikipedia.org/wiki/system of linear equations" title="wp: system of linear equations">system of linear equations</a> 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 <a href="https://en.wikipedia.org/wiki/linear algebra" title="wp: linear algebra" target="_blank">linear algebra</a>, <a href="https://en.wikipedia.org/wiki/Cramer's rule" title="wp: Cramer's rule" target="_blank">Cramer's rule</a> is an explicit formula for the solution of a <a href="https://en.wikipedia.org/wiki/system of linear equations" title="wp: system of linear equations" target="_blank">system of linear equations</a> 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
|
||||
<big>
|
||||
$\left\{\begin{matrix}a_1x + b_1y + c_1z&= {\color{red}d_1}\\a_2x + b_2y + c_2z&= {\color{red}d_2}\\a_3x + b_3y + c_3z&= {\color{red}d_3}\end{matrix}\right.$
|
||||
|
@ -8,7 +8,7 @@ challengeType: 5
|
||||
<section id='description'>
|
||||
A given rectangle is made from <i>m</i> × <i>n</i> squares. If <i>m</i> and <i>n</i> are not both odd, then it is possible to cut a path through the rectangle along the square edges such that the rectangle splits into two connected pieces with the same shape (after rotating one of the pieces by 180°). All such paths for 2 × 2 and 4 × 3 rectangles are shown below.
|
||||
<div style="width: 100%; text-align: center;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="520" height="170" aria-hidden="true" alt="Diagram showing the possible paths for 2 by 2 and 4 by 3 rectangles">
|
||||
<svg xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink" width="520" height="170" aria-hidden="true" alt="Diagram showing the possible paths for 2 by 2 and 4 by 3 rectangles">
|
||||
<style>
|
||||
.g { fill: none; stroke: #ccc }
|
||||
.s, .s2 { fill: #bff; stroke: black; fill-opacity: .4 }
|
@ -6,9 +6,9 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<i>FreeCell</i> is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for <a href="https://rosettacode.org/wiki/DOS" title="DOS">DOS</a>, then <a href="https://rosettacode.org/wiki/Windows" title="Windows">Windows</a>. This version introduced 32000 numbered deals. (The <a href="https://www.solitairelaboratory.com/fcfaq.html">FreeCell FAQ</a> tells this history.)
|
||||
As the game became popular, Jim Horne disclosed <a href="https://www.solitairelaboratory.com/mshuffle.txt">the algorithm</a>, 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 <a href="https://rosettacode.org/wiki/linear congruential generator" title="linear congruential generator">linear congruential generator</a> from Microsoft C:
|
||||
<i>FreeCell</i> is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for <a href="https://rosettacode.org/wiki/DOS" title="DOS" target="_blank">DOS</a>, then <a href="https://rosettacode.org/wiki/Windows" title="Windows" target="_blank">Windows</a>. This version introduced 32000 numbered deals.
|
||||
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 <a href="https://rosettacode.org/wiki/linear congruential generator" title="linear congruential generator" target="_blank">linear congruential generator</a> from Microsoft C:
|
||||
<ul>
|
||||
<li>$state_{n + 1} \equiv 214013 \times state_n + 2531011 \pmod{2^{31}}$</li>
|
||||
<li>$rand_n = state_n \div 2^{16}$</li>
|
||||
@ -17,7 +17,7 @@ The algorithm uses this <a href="https://rosettacode.org/wiki/linear congruentia
|
||||
The algorithm follows:
|
||||
<ol>
|
||||
<li>Seed the RNG with the number of the deal.
|
||||
<li>Create an <a href="https://rosettacode.org/wiki/array" title="array">array</a> of 52 cards: Ace of Clubs, Ace of Diamonds, Ace of Hearts, Ace of Spades, 2 of Clubs, 2 of Diamonds, and so on through the ranks: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King. The array indexes are 0 to 51, with Ace of Clubs at 0, and King of Spades at 51.</li>
|
||||
<li>Create an <a href="https://rosettacode.org/wiki/array" title="array" target="_blank">array</a> of 52 cards: Ace of Clubs, Ace of Diamonds, Ace of Hearts, Ace of Spades, 2 of Clubs, 2 of Diamonds, and so on through the ranks: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King. The array indexes are 0 to 51, with Ace of Clubs at 0, and King of Spades at 51.</li>
|
||||
<li>Until the array is empty:</li>
|
||||
<li>Choose a random card at index ≡ next random number (mod array length).</li>
|
||||
<ul>
|
||||
@ -37,31 +37,37 @@ The algorithm follows:
|
||||
41 42 43 44 45 46 47 48
|
||||
49 50 51 52</pre>
|
||||
<b>Game #1</b>
|
||||
<pre>[
|
||||
['JD', '2D', '9H', 'JC', '5D', '7H', '7C', '5H'],
|
||||
['KD', 'KC', '9S', '5S', 'AD', 'QC', 'KH', '3H'],
|
||||
['2S', 'KS', '9D', 'QD', 'JS', 'AS', 'AH', '3C'],
|
||||
['4C', '5C', 'TS', 'QH', '4H', 'AC', '4D', '7S'],
|
||||
['3S', 'TD', '4S', 'TH', '8H', '2C', 'JH', '7D'],
|
||||
['6D', '8S', '8D', 'QS', '6C', '3D', '8C', 'TC'],
|
||||
['6S', '9C', '2H', '6H']
|
||||
]</pre>
|
||||
|
||||
```js
|
||||
[
|
||||
['JD', '2D', '9H', 'JC', '5D', '7H', '7C', '5H'],
|
||||
['KD', 'KC', '9S', '5S', 'AD', 'QC', 'KH', '3H'],
|
||||
['2S', 'KS', '9D', 'QD', 'JS', 'AS', 'AH', '3C'],
|
||||
['4C', '5C', 'TS', 'QH', '4H', 'AC', '4D', '7S'],
|
||||
['3S', 'TD', '4S', 'TH', '8H', '2C', 'JH', '7D'],
|
||||
['6D', '8S', '8D', 'QS', '6C', '3D', '8C', 'TC'],
|
||||
['6S', '9C', '2H', '6H']
|
||||
]
|
||||
```
|
||||
<b>Game #617</b>
|
||||
<pre>[
|
||||
['7D', 'AD', '5C', '3S', '5S', '8C', '2D', 'AH'],
|
||||
['TD', '7S', 'QD', 'AC', '6D', '8H', 'AS', 'KH'],
|
||||
['TH', 'QC', '3H', '9D', '6S', '8D', '3D', 'TC'],
|
||||
['KD', '5H', '9S', '3C', '8S', '7H', '4D', 'JS'],
|
||||
['4C', 'QS', '9C', '9H', '7C', '6H', '2C', '2S'],
|
||||
['4S', 'TS', '2H', '5D', 'JC', '6C', 'JH', 'QH'],
|
||||
['JD', 'KS', 'KC', '4H']
|
||||
]</pre>
|
||||
|
||||
```js
|
||||
[
|
||||
['7D', 'AD', '5C', '3S', '5S', '8C', '2D', 'AH'],
|
||||
['TD', '7S', 'QD', 'AC', '6D', '8H', 'AS', 'KH'],
|
||||
['TH', 'QC', '3H', '9D', '6S', '8D', '3D', 'TC'],
|
||||
['KD', '5H', '9S', '3C', '8S', '7H', '4D', 'JS'],
|
||||
['4C', 'QS', '9C', '9H', '7C', '6H', '2C', '2S'],
|
||||
['4S', 'TS', '2H', '5D', 'JC', '6C', 'JH', 'QH'],
|
||||
['JD', 'KS', 'KC', '4H']
|
||||
]
|
||||
```
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Write a function to take a deal number and deal cards in the same order as this algorithm. The function must return a two dimensional array representing the FreeCell board.
|
||||
Deals can also be checked against <a href="https://freecellgamesolutions.com/">FreeCell solutions to 1000000 games</a>. (Summon a video solution, and it displays the initial deal.)
|
||||
Deals can also be checked against <a href="https://freecellgamesolutions.com/" target="_blank">FreeCell solutions to 1000000 games</a>. (Summon a video solution, and it displays the initial deal.)
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
|
@ -19,14 +19,15 @@ The Chief of the Police doesn't like odd numbers and wants to have an even numbe
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Write a program which outputs all valid combinations:
|
||||
<blockquote>
|
||||
[2, 3, 7] [2, 4, 6] [2, 6, 4]<br>
|
||||
[2, 7, 3] [4, 1, 7] [4, 2, 6]<br>
|
||||
[4, 3, 5] [4, 5, 3] [4, 6, 2]<br>
|
||||
[4, 7, 1] [6, 1, 5] [6, 2, 4]<br>
|
||||
Write a program which outputs all valid combinations as an array.
|
||||
|
||||
```js
|
||||
[2, 3, 7] [2, 4, 6] [2, 6, 4]
|
||||
[2, 7, 3] [4, 1, 7] [4, 2, 6]
|
||||
[4, 3, 5] [4, 5, 3] [4, 6, 2]
|
||||
[4, 7, 1] [6, 1, 5] [6, 2, 4]
|
||||
[6, 4, 2] [6, 5, 1]
|
||||
</blockquote>
|
||||
```
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
|
@ -6,7 +6,7 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Convert a given date from the <a href="https://en.wikipedia.org/wiki/Gregorian calendar" title="wp: Gregorian calendar">Gregorian calendar</a> to the <a href="https://en.wikipedia.org/wiki/Discordian calendar" title="wp: Discordian calendar">Discordian calendar</a>.
|
||||
Convert a given date from the <a href="https://en.wikipedia.org/wiki/Gregorian calendar" title="wp: Gregorian calendar" target="_blank">Gregorian calendar</a> to the <a href="https://en.wikipedia.org/wiki/Discordian calendar" title="wp: Discordian calendar" target="_blank">Discordian calendar</a>.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -7,7 +7,7 @@ challengeType: 5
|
||||
## Description
|
||||
<section id='description'>
|
||||
Write a function to implement a Brain**** interpreter. The function will take a string as a parameter and should return a string as the output. More details are given below:
|
||||
RCBF is a set of <a href="https://rosettacode.org/wiki/Brainf***" title="Brainf***">Brainf***</a> compilers and interpreters written for Rosetta Code in a variety of languages.
|
||||
RCBF is a set of <a href="https://rosettacode.org/wiki/Brainf***" title="Brainf***" target="_blank">Brainf***</a> compilers and interpreters written for Rosetta Code in a variety of languages.
|
||||
Below are links to each of the versions of RCBF.
|
||||
An implementation need only properly implement the following instructions:
|
||||
|
||||
|
@ -6,7 +6,7 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Write a generalized version of <a href="https://rosettacode.org/wiki/FizzBuzz">FizzBuzz</a> that works for any list of factors, along with their words.
|
||||
Write a generalized version of <a href="https://rosettacode.org/wiki/FizzBuzz" target="_blank">FizzBuzz</a> that works for any list of factors, along with their words.
|
||||
This is basically a "fizzbuzz" implementation where the rules of the game are supplied to the user. Create a function to implement this. The function should take two parameters.
|
||||
The first will be an array with the FizzBuzz rules. For example: <code>[ [3, "Fizz"] , [5, "Buzz"] ]</code>.
|
||||
This indcates that <code>Fizz</code> should be printed if the number is a multiple of 3 and <code>Buzz</code> if it is a multiple of 5. If it is a multiple of both then the strings should be concatenated in the order specified in the array. In this case, <code>FizzBuzz</code> if the number is a multiple of 3 and 5.
|
||||
|
@ -6,8 +6,8 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
The <a href="https://mathworld.wolfram.com/HarshadNumber.html" target="_blank">Harshad</a> 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/oeis:A005349" title="oeis:A005349" target="_blank">Harshad number</a> as <b>42</b> is divisible by <b>(4 + 2)</b> without remainder.
|
||||
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.
|
||||
Assume that the series is defined as the numbers in increasing order.
|
||||
</section>
|
||||
|
||||
|
@ -6,7 +6,7 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
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">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.
|
||||
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>
|
||||
|
@ -10,7 +10,7 @@ challengeType: 5
|
||||
<span style="margin-left: 2em;"><big>$A = \sqrt{s(s-a)(s-b)(s-c)},$</big></span>
|
||||
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>
|
||||
<a href="https://www.had2know.com/academics/heronian-triangles-generator-calculator.html" target="_blank">Heronian triangles</a> are triangles whose sides and area are all integers.
|
||||
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.
|
||||
Define a Primitive Heronian triangle as a Heronian triangle where the greatest common divisor
|
||||
|
@ -24,9 +24,6 @@ No maximum value for <b>n</b> should be assumed.
|
||||
<li>
|
||||
Sloane's <a href="https://oeis.org/A005228" target="_blank">A005228</a> and <a href="https://oeis.org/A030124" target="_blank">A030124</a>.
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://mathworld.wolfram.com/HofstadterFigure-FigureSequence.html" target="_blank">Wolfram MathWorld</a>
|
||||
</li>
|
||||
<li>
|
||||
Wikipedia: <a href="https://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Figure-Figure_sequences" title="wp: Hofstadter_sequence#Hofstadter_Figure-Figure_sequences" target="_blank">Hofstadter Figure-Figure sequences</a>.
|
||||
</li>
|
||||
|
@ -8,14 +8,14 @@ challengeType: 5
|
||||
<section id='description'>
|
||||
A positive integer is a <a href="https://en.wikipedia.org/wiki/Kaprekar number">Kaprekar number</a> if:
|
||||
<ul>
|
||||
<li>It is 1, or,</li>
|
||||
<li>The decimal representation of its square may be split once into two parts consisting of positive integers which sum to the original number. </li>
|
||||
<li>It is 1, or,</li>
|
||||
<li>The decimal representation of its square may be split once into two parts consisting of positive integers which sum to the original number. </li>
|
||||
</ul>
|
||||
Note that a split resulting in a part consisting purely of 0s is not valid, as 0 is not considered positive.Example
|
||||
Kaprekar numbers:
|
||||
<ul>
|
||||
<li> <code>2223</code> is a Kaprekar number, as <code>2223 * 2223 = 4941729</code>, <code>4941729</code> may be split to <code>494</code> and <code>1729</code>, and <code>494 + 1729 = 2223</code></li>
|
||||
<li>The series of Kaprekar numbers is known as <a href="https://rosettacode.org/wiki/oeis:A006886">A006886</a>, and begins as <code>1, 9, 45, 55, ...</code></li>
|
||||
<li><code>2223</code> is a Kaprekar number, as <code>2223 * 2223 = 4941729</code>, <code>4941729</code> may be split to <code>494</code> and <code>1729</code>, and <code>494 + 1729 = 2223</code></li>
|
||||
<li>The series of Kaprekar numbers is known as <a href="https://oeis.org/A006886" target="_blank">A006886</a>, and begins as <code>1, 9, 45, 55, ...</code></li>
|
||||
</ul>
|
||||
</section>
|
||||
|
@ -8,7 +8,7 @@ challengeType: 5
|
||||
<section id='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 <i>m</i> or <i>n</i> is zero, then the least common multiple is zero.
|
||||
One way to calculate the least common multiple is to iterate all the multiples of <i>m</i>, until you find one that is also a multiple of <i>n</i>.
|
||||
If you already have <i>gcd</i> for <a href="https://rosettacode.org/wiki/greatest common divisor">greatest common divisor</a>, then this formula calculates <i>lcm</i>.
|
||||
If you already have <i>gcd</i> for <a href="https://rosettacode.org/wiki/greatest common divisor" target="_blank">greatest common divisor</a>, then this formula calculates <i>lcm</i>.
|
||||
\( \operatorname{lcm}(m, n) = \frac{|m \times n|}{\operatorname{gcd}(m, n)} \)
|
||||
</section>
|
||||
|
@ -8,9 +8,9 @@ challengeType: 5
|
||||
<section id='description'>
|
||||
<b>Left factorials</b>, $ !n $, may refer to either <i>subfactorials</i> or to <i>factorial sums</i>. The same notation can be confusingly seen used for the two different definitions. Sometimes, <i>subfactorials</i> (also known as <i>derangements</i>) may use any of the notations:
|
||||
<ul>
|
||||
<li>$!n`$</li>
|
||||
<li>$!n$</li>
|
||||
<li>$n¡$</li>
|
||||
<li>$!n`$</li>
|
||||
<li>$!n$</li>
|
||||
<li>$n¡$</li>
|
||||
</ul>
|
||||
(It may not be visually obvious, but the last example uses an upside-down exclamation mark.) This task will be using this formula for <b>left factorial</b>:
|
||||
$ !n = \sum_{k=0}^{n-1} k! $
|
@ -15,7 +15,7 @@ Write a simple reader/parser for S-Expressions that handles quoted and unquoted
|
||||
The function should read a single but nested S-Expression from a string and return it as a (nested) array.
|
||||
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>" maybe treated as a string "<tt>foo"bar</tt>", or as an error.
|
||||
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.
|
||||
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
|
||||
|
@ -32,9 +32,9 @@ Pseudocode:
|
||||
gap := 1
|
||||
<b>end if</b>
|
||||
i := 0
|
||||
swaps := 0 <i>//see <a href="https://rosettacode.org/wiki/Bubble Sort">Bubble Sort</a> for an explanation</i>
|
||||
swaps := 0 <i>//see <a href="https://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort" target="_blank">Bubble Sort</a> for an explanation</i>
|
||||
<i>//a single "comb" over the input list</i>
|
||||
<b>loop until</b> i + gap >= input<b>.size</b> <i>//see <a href="https://rosettacode.org/wiki/Shell sort">Shell sort</a> for similar idea</i>
|
||||
<b>loop until</b> i + gap >= input<b>.size</b> <i>//see <a href="https://rosettacode.org/wiki/Sorting_algorithms/Shell_sort" target="_blank">Shell sort</a> for similar idea</i>
|
||||
<b>if</b> input[i] > input[i+gap]
|
||||
<b>swap</b>(input[i], input[i+gap])
|
||||
swaps := 1 <i>// Flag a swap has occurred, so the</i>
|
@ -6,10 +6,10 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
This task is inspired by <a href="https://drdobbs.com/windows/198701685" target="_blank">Mark Nelson's DDJ Column "Wordplay"</a> and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition <a href="https://www.npr.org/templates/story/story.php?storyId=9264290"target="_blank">[1]</a> and originally attributed to David Edelheit.
|
||||
This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition <a href="https://www.npr.org/templates/story/story.php?storyId=9264290" target="_blank">[1]</a> and originally attributed to David Edelheit.
|
||||
The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the names of two <i>different</i> U.S. States (so that all four state names differ from one another).
|
||||
What states are these?
|
||||
The problem was reissued on <a href="https://tapestry.tucson.az.us/twiki/bin/view/Main/StateNamesPuzzle" target="_blank">the Unicon Discussion Web</a> which includes several solutions with analysis. Several techniques may be helpful and you may wish to refer to <a href="https://en.wikipedia.org/wiki/Goedel_numbering">Gödel numbering</a>, <a href="https://en.wikipedia.org/wiki/Equivalence_relation" target="_blank">equivalence relations</a>, and <a href="https://en.wikipedia.org/wiki/Equivalence_classes" target="_blank">equivalence classes</a>. The basic merits of these were discussed in the Unicon Discussion Web.
|
||||
The problem was reissued on <a href="https://tapestry.tucson.az.us/twiki/bin/view/Main/StateNamesPuzzle" target="_blank">the Unicon Discussion Web</a> which includes several solutions with analysis. Several techniques may be helpful and you may wish to refer to <a href="https://en.wikipedia.org/wiki/Goedel_numbering" target="_blank">Gödel numbering</a>, <a href="https://en.wikipedia.org/wiki/Equivalence_relation" target="_blank">equivalence relations</a>, and <a href="https://en.wikipedia.org/wiki/Equivalence_classes" target="_blank">equivalence classes</a>. The basic merits of these were discussed in the Unicon Discussion Web.
|
||||
A second challenge in the form of a set of fictitious new states was also presented.
|
||||
</section>
|
||||
|
@ -11,9 +11,9 @@ Informally this value, or its limit when <b>n</b> tends to infinity, is also c
|
||||
For this task, use:
|
||||
<span style="margin-left: 2em;">$S_n = \sum_{k=1}^n \frac{1}{k^2}$</span>
|
||||
and compute $S_{1000}$
|
||||
This approximates the <a href="https://en.wikipedia.org/wiki/Riemann zeta function">zeta function</a> for S=2, whose exact value
|
||||
This approximates the <a href="https://en.wikipedia.org/wiki/Riemann zeta function" target="_blank">zeta function</a> for S=2, whose exact value
|
||||
<span style="margin-left: 2em;">$\zeta(2) = {\pi^2\over 6}$</span>
|
||||
is the solution of the <a href="https://en.wikipedia.org/wiki/Basel problem">Basel problem</a>.
|
||||
is the solution of the <a href="https://en.wikipedia.org/wiki/Basel problem" target="_blank">Basel problem</a>.
|
||||
</section>
|
||||
|
||||
## Instructions
|
@ -25,8 +25,6 @@ Write a function that returns the lowest <code>n</code> taxicab numbers. For eac
|
||||
<b>See also:</b>
|
||||
<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://mathworld.wolfram.com/Hardy-RamanujanNumber.html" target="_blank">Hardy-Ramanujan Number</a> on MathWorld.</li>
|
||||
<li><a href="https://mathworld.wolfram.com/TaxicabNumber.html" target="_blank">taxicab number</a> on MathWorld.</li>
|
||||
<li><a href="https://en.wikipedia.org/wiki/Taxicab_number" target="_blank">taxicab number</a> on Wikipedia.</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
@ -12,7 +12,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">factorial</a>. The <code>factorial(N)</code> function is already given to you.
|
||||
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>
|
||||
<ul>
|
||||
<li><a href="https://vimeo.com/45140590" target="_blank">Jim Weirich: Adventures in Functional Programming</a>.</li>
|
||||
|
Reference in New Issue
Block a user