fix(challenges): Went back and fixed a missing A problem. Fixed C problems.
This commit is contained in:
parent
f9f4048258
commit
d024b96a92
@ -9,12 +9,12 @@ challengeType: 5
|
||||
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).
|
||||
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='http://rosettacode.org/wiki/Averages/Arithmetic mean' title='Averages/Arithmetic mean'>arithmetic mean</a>, is the sum of the list divided by its length:<br>
|
||||
<big>$ A(x_1, \ldots, x_n) = \frac{x_1 + \cdots + x_n}{n}$</big></li>
|
||||
<li>The <a class='rosetta__link--wiki' href='https://en.wikipedia.org/wiki/Geometric mean' title='wp: Geometric mean'>geometric mean</a> is the $n$th root of the product of the list:<br>
|
||||
<big>$ G(x_1, \ldots, x_n) = \sqrt[n]{x_1 \cdots x_n} $</big></li>
|
||||
<li>The <a class='rosetta__link--wiki' href='https://en.wikipedia.org/wiki/Harmonic mean' title='wp: Harmonic mean'>harmonic mean</a> is $n$ divided by the sum of the reciprocal of each item in the list:<br>
|
||||
<big>$ H(x_1, \ldots, x_n) = \frac{n}{\frac{1}{x_1} + \cdots + \frac{1}{x_n}} $</big></li>
|
||||
<li>The most common of the three means, the <a class='rosetta__link--rosetta' href='http://rosettacode.org/wiki/Averages/Arithmetic mean' title='Averages/Arithmetic mean'>arithmetic mean</a>, is the sum of the list divided by its length:<br>
|
||||
<big>$ A(x_1, \ldots, x_n) = \frac{x_1 + \cdots + x_n}{n}$</big></li>
|
||||
<li>The <a class='rosetta__link--wiki' href='https://en.wikipedia.org/wiki/Geometric mean' title='wp: Geometric mean'>geometric mean</a> is the $n$th root of the product of the list:<br>
|
||||
<big>$ G(x_1, \ldots, x_n) = \sqrt[n]{x_1 \cdots x_n} $</big></li>
|
||||
<li>The <a class='rosetta__link--wiki' href='https://en.wikipedia.org/wiki/Harmonic mean' title='wp: Harmonic mean'>harmonic mean</a> is $n$ divided by the sum of the reciprocal of each item in the list:<br>
|
||||
<big>$ H(x_1, \ldots, x_n) = \frac{n}{\frac{1}{x_1} + \cdots + \frac{1}{x_n}} $</big></li>
|
||||
</ul>
|
||||
Assume the input is an ordered array of all inclusive numbers.
|
||||
For the answer, please output an object in the following format:
|
||||
|
@ -6,9 +6,10 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>Compute the <a href="https://en.wikipedia.org/wiki/Root mean square" title="wp: Root mean square">Root mean square</a> of the numbers 1 through 10 inclusive.</p>
|
||||
<p>The root mean square is also known by its initials RMS (or rms), and as the quadratic mean.</p><p>The RMS is calculated as the mean of the squares of the numbers, square-rooted:</p>
|
||||
<p><big>$$x_{\mathrm{rms}} = \sqrt {{{x_1}^2 + {x_2}^2 + \cdots + {x_n}^2} \over n}. $$</big></p>
|
||||
Compute the <a href="https://en.wikipedia.org/wiki/Root mean square" title="wp: Root mean square">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 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>
|
||||
|
||||
## Instructions
|
||||
|
@ -6,12 +6,14 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p><a href="https://en.wikipedia.org/wiki/Charles_Babbage" title="wp: Charles_Babbage">Charles Babbage</a>, looking ahead to the sorts of problems his Analytical Engine would be able to solve, gave this example:</p>
|
||||
<blockquote>What is the smallest positive integer whose square ends in the digits 269,696?</blockquote>
|
||||
<p> - Babbage, letter to Lord Bowden, 1837; see Hollingdale and Tootill, <i>Electronic Computers</i>, second edition, 1970, p. 125.</p>
|
||||
<p>He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain.</p>
|
||||
<p>The task is to find out if Babbage had the right answer.</p>
|
||||
<p>Implement a function to return the lowest integer that satisfies the Babbage problem. If Babbage was right, return Babbage's number.</p>
|
||||
<a href="https://en.wikipedia.org/wiki/Charles_Babbage" title="wp: Charles_Babbage">Charles Babbage</a>, looking ahead to the sorts of problems his Analytical Engine would be able to solve, gave this example:
|
||||
<blockquote>
|
||||
What is the smallest positive integer whose square ends in the digits 269,696?
|
||||
<footer>Babbage, letter to Lord Bowden, 1837; see Hollingdale and Tootill, <i>Electronic Computers</i>, second edition, 1970, p. 125.</footer>
|
||||
</blockquote>
|
||||
He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain.
|
||||
The task is to find out if Babbage had the right answer.
|
||||
Implement a function to return the lowest integer that satisfies the Babbage problem. If Babbage was right, return Babbage's number.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -6,15 +6,17 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>Determine whether a generated string of brackets is balanced; that is, whether it consists entirely of pairs of opening/closing brackets (in that order), none of which mis-nest.</p>
|
||||
Determine whether a generated string of brackets is balanced; that is, whether it consists entirely of pairs of opening/closing brackets (in that order), none of which mis-nest.
|
||||
Examples:
|
||||
<p class='rosetta__paragraph'>(empty) true</p>
|
||||
<p class='rosetta__paragraph'><code>[]</code> true</p>
|
||||
<p class='rosetta__paragraph'><code>][</code> false</p>
|
||||
<p class='rosetta__paragraph'><code>[][]</code> true</p>
|
||||
<p class='rosetta__paragraph'><code>][][</code> false</p>
|
||||
<p class='rosetta__paragraph'><code>[]][[]</code> false</p>
|
||||
<p class='rosetta__paragraph'><code>[[[[]]]]</code> true</p>
|
||||
<pre>
|
||||
(empty) true
|
||||
<code>[]</code> true
|
||||
<code>][</code> false
|
||||
<code>[][]</code> true
|
||||
<code>][][</code> false
|
||||
<code>[]][[]</code> false
|
||||
<code>[[[[]]]]</code> true
|
||||
</pre>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -6,18 +6,23 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.</p>
|
||||
Exceptions:
|
||||
A radius of zero should be treated as never describing circles (except in the case where the points are coincident).
|
||||
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.
|
||||
If the points form a diameter then return a single circle.
|
||||
If the points are too far apart then no circles can be drawn.Task:
|
||||
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
|
||||
<b>Exceptions:</b>
|
||||
<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>
|
||||
<li>If the points form a diameter then return a single circle.</li>
|
||||
<li>If the points are too far apart then no circles can be drawn.</li>
|
||||
</ul>
|
||||
<b>Task:</b>
|
||||
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.
|
||||
For edge cases, return the following:
|
||||
If points are on the diameter, return one point. If the radius is also zero however, return <code>"Radius Zero"</code>.
|
||||
If points are coincident, return <code>"Coincident point. Infinite solutions"</code>.
|
||||
If points are farther apart than the diameter, return <code>"No intersection. Points further apart than circle diameter"</code>.
|
||||
Sample inputs:
|
||||
<b>For edge cases, return the following:</b>
|
||||
<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>
|
||||
<pre>
|
||||
p1 p2 r
|
||||
0.1234, 0.9876 0.8765, 0.2345 2.0
|
||||
@ -26,7 +31,7 @@ Sample inputs:
|
||||
0.1234, 0.9876 0.8765, 0.2345 0.5
|
||||
0.1234, 0.9876 0.1234, 0.9876 0.0
|
||||
</pre>
|
||||
Ref:
|
||||
<b>Ref:</b>
|
||||
<a href="http://mathforum.org/library/drmath/view/53027.html" title="link: http://mathforum.org/library/drmath/view/53027.html">Finding the Center of a Circle from 2 Points and Radius</a> from Math forum @ Drexel
|
||||
</section>
|
||||
|
||||
|
@ -6,34 +6,34 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Task:
|
||||
<p>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 planar case.</p><p>The straightforward solution is a O(n<sup>2</sup>) algorithm (which we can call brute-force algorithm); the pseudo-code (using indexes) could be simply:</p>
|
||||
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.
|
||||
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>
|
||||
bruteForceClosestPair of P(1), P(2), ... P(N)
|
||||
if N < 2 then
|
||||
return ∞
|
||||
else
|
||||
<b>bruteForceClosestPair</b> of P(1), P(2), ... P(N)
|
||||
<b>if</b> N < 2 <b>then</b>
|
||||
<b>return</b> ∞
|
||||
<b>else</b>
|
||||
minDistance ← |P(1) - P(2)|
|
||||
minPoints ← { P(1), P(2) }
|
||||
foreach i ∈ [1, N-1]
|
||||
foreach j ∈ [i+1, N]
|
||||
if |P(i) - P(j)| < minDistance then
|
||||
<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>
|
||||
minDistance ← |P(i) - P(j)|
|
||||
minPoints ← { P(i), P(j) }
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
return minDistance, minPoints
|
||||
endif
|
||||
<b>endif</b>
|
||||
<b>endfor</b>
|
||||
<b>endfor</b>
|
||||
<b>return</b> minDistance, minPoints
|
||||
<b>endif</b>
|
||||
</pre>
|
||||
<p>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(n log n); a pseudo-code could be:</p>
|
||||
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:
|
||||
<pre>
|
||||
closestPair of (xP, yP)
|
||||
<b>closestPair</b> 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)
|
||||
if N ≤ 3 then
|
||||
return closest points of xP using brute-force algorithm
|
||||
else
|
||||
<b>if</b> N ≤ 3 <b>then</b>
|
||||
<b>return</b> closest points of xP using brute-force algorithm
|
||||
<b>else</b>
|
||||
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,31 +42,33 @@ else
|
||||
(dL, pairL) ← closestPair of (xL, yL)
|
||||
(dR, pairR) ← closestPair of (xR, yR)
|
||||
(dmin, pairMin) ← (dR, pairR)
|
||||
if dL < dR then
|
||||
<b>if</b> dL < dR <b>then</b>
|
||||
(dmin, pairMin) ← (dL, pairL)
|
||||
endif
|
||||
<b>endif</b>
|
||||
yS ← { p ∈ yP : |xm - p<sub>x</sub>| < dmin }
|
||||
nS ← number of points in yS
|
||||
(closest, closestPair) ← (dmin, pairMin)
|
||||
for i from 1 to nS - 1
|
||||
<b>for</b> i <b>from</b> 1 <b>to</b> nS - 1
|
||||
k ← i + 1
|
||||
while k ≤ nS and yS(k)<sub>y</sub> - yS(i)<sub>y</sub> < dmin
|
||||
if |yS(k) - yS(i)| < closest then
|
||||
<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>
|
||||
(closest, closestPair) ← (|yS(k) - yS(i)|, {yS(k), yS(i)})
|
||||
endif
|
||||
<b>endif</b>
|
||||
k ← k + 1
|
||||
endwhile
|
||||
endfor
|
||||
return closest, closestPair
|
||||
endif
|
||||
<b>endwhile</b>
|
||||
<b>endfor</b>
|
||||
<b>return</b> closest, closestPair
|
||||
<b>endif</b>
|
||||
</pre>
|
||||
References and further readings:
|
||||
<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>
|
||||
<a href="http://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html" title="link: http://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html">Closest Pair (McGill)</a>
|
||||
<a href="http://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf" title="link: http://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf">Closest Pair (UCSB)</a>
|
||||
<a href="http://classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf" title="link: http://classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf">Closest pair (WUStL)</a>
|
||||
<a href="http://www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt" title="link: http://www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt">Closest pair (IUPUI)</a>
|
||||
<p>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> (i.e., the pair of two closest points).</p>
|
||||
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="http://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html" title="link: http://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html">Closest Pair (McGill)</a></li>
|
||||
<li><a href="http://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf" title="link: http://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf">Closest Pair (UCSB)</a></li>
|
||||
<li><a href="http://classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf" title="link: http://classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf">Closest pair (WUStL)</a></li>
|
||||
<li><a href="http://www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt" title="link: http://www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt">Closest pair (IUPUI)</a></li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -6,10 +6,9 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Task:
|
||||
<p>Given non-negative integers <big> m </big> and <big> n</big>, generate all size <big> m </big> <a href="http://mathworld.wolfram.com/Combination.html" title="link: http://mathworld.wolfram.com/Combination.html">combinations</a> of the integers from <big> 0</big> (zero) to <big> n-1 </big> in sorted order (each combination is sorted and the entire table is sorted).</p>
|
||||
Example:
|
||||
<p><big>3</big> comb <big> 5 </big>is:</p>
|
||||
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="http://mathworld.wolfram.com/Combination.html" title="link: http://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).
|
||||
<b>Example:</b>
|
||||
<big><b>3</b></big> comb <big><b>5</b></big> is:
|
||||
<pre>
|
||||
0 1 2
|
||||
0 1 3
|
||||
|
@ -6,18 +6,22 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>Comma quibbling is a task originally set by Eric Lippert in his <a href="http://blogs.msdn.com/b/ericlippert/archive/2009/04/15/comma-quibbling.aspx" title="link: http://blogs.msdn.com/b/ericlippert/archive/2009/04/15/comma-quibbling.aspx">blog</a>.</p>
|
||||
Task:<p>Write a function to generate a string output which is the concatenation of input words from a list/sequence where:</p>
|
||||
An input of no words produces the output string of just the two brace characters "{}".
|
||||
An input of just one word, e.g. ["ABC"], produces the output string of the word inside the two braces, e.g. "{ABC}".
|
||||
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}".
|
||||
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}".
|
||||
<p>Test your function with the following series of inputs showing your output here on this page:</p>
|
||||
[] # (No input words).
|
||||
["ABC"]
|
||||
["ABC", "DEF"]
|
||||
["ABC", "DEF", "G", "H"]
|
||||
<p>Note: Assume words are non-empty strings of uppercase characters for this task.</p>
|
||||
Comma quibbling is a task originally set by Eric Lippert in his <a href="http://blogs.msdn.com/b/ericlippert/archive/2009/04/15/comma-quibbling.aspx" title="link: http://blogs.msdn.com/b/ericlippert/archive/2009/04/15/comma-quibbling.aspx">blog</a>.
|
||||
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>
|
||||
</ol>
|
||||
Test your function with the following series of inputs showing your output here on this page:
|
||||
<ul>
|
||||
<li>[] # (No input words).</li>
|
||||
<li>["ABC"]</li>
|
||||
<li>["ABC", "DEF"]</li>
|
||||
<li>["ABC", "DEF", "G", "H"]</li>
|
||||
</ul>
|
||||
Note: Assume words are non-empty strings of uppercase characters for this task.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -6,8 +6,11 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>Given a <a href="https://en.wikipedia.org/wiki/List_(abstract_data_type)" title="wp: List_(abstract_data_type)">list</a> of arbitrarily many strings, implement a function for each of the following conditions:</p> test if they are all lexically equal
|
||||
test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order)
|
||||
Given a <a href="https://en.wikipedia.org/wiki/List_(abstract_data_type)" title="wp: List_(abstract_data_type)">list</a> of arbitrarily many strings, implement a function for each of the following conditions:
|
||||
<ul>
|
||||
<li>test if they are all lexically equal</li>
|
||||
<li>test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order)</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -6,69 +6,82 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Task:
|
||||
<p>Implement a function which:</p>
|
||||
takes a positive integer representing a duration in seconds as input (e.g., <code>100</code>), and
|
||||
returns a string which shows the same duration decomposed into weeks, days, hours, minutes, and seconds as detailed below (e.g., <code>1 min, 40 sec</code>).
|
||||
<p>Demonstrate that it passes the following three test-cases:</p><p style="font-size:115%; margin:1em 0 0 0">Test Cases</p>
|
||||
Implement a function which:
|
||||
<ul>
|
||||
<li>takes a positive integer representing a duration in seconds as input (e.g., <code>100</code>), and</li>
|
||||
<li>returns a string which shows the same duration decomposed into weeks, days, hours, minutes, and seconds as detailed below (e.g., <code>1 min, 40 sec</code>).</li>
|
||||
</ul>
|
||||
Demonstrate that it passes the following three test-cases:
|
||||
<div style="font-size:115%; font-weight: bold;">Test Cases</div>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>input number</th>
|
||||
<th>output number</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>7259</td>
|
||||
<td><code>2 hr, 59 sec</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>86400</td>
|
||||
<td><code>1 d</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>6000000</td>
|
||||
<td><code>9 wk, 6 d, 10 hr, 40 min</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>input number</th>
|
||||
<th>output number</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>7259</td>
|
||||
<td><code>2 hr, 59 sec</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>86400</td>
|
||||
<td><code>1 d</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>6000000</td>
|
||||
<td><code>9 wk, 6 d, 10 hr, 40 min</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p style="font-size:115%; margin:1em 0 0 0">Details</p>
|
||||
The following five units should be used:
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>unit</th>
|
||||
<th>suffix used in output</th>
|
||||
<th>conversion</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>week</td>
|
||||
<td><code>wk</code></td>
|
||||
<td>1 week = 7 days</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>day</td>
|
||||
<td><code>d</code></td>
|
||||
<td>1 day = 24 hours</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>hour</td>
|
||||
<td><code>hr</code></td>
|
||||
<td>1 hour = 60 minutes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>minute</td>
|
||||
<td><code>min</code></td>
|
||||
<td>1 minute = 60 seconds</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>second</td>
|
||||
<td><code>sec</code></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
However, only 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>).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>)Mimic the formatting shown in the test-cases (quantities sorted from largest unit to smallest and separated by comma+space; value and unit of each quantity separated by space).
|
||||
<p><hr style="margin:1em 0;"/></p>
|
||||
<div style="font-size:115%; font-weight: bold;">Details</div>
|
||||
<ul>
|
||||
<li>
|
||||
The following five units should be used:
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>unit</th>
|
||||
<th>suffix used in output</th>
|
||||
<th>conversion</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>week</td>
|
||||
<td><code>wk</code></td>
|
||||
<td>1 week = 7 days</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>day</td>
|
||||
<td><code>d</code></td>
|
||||
<td>1 day = 24 hours</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>hour</td>
|
||||
<td><code>hr</code></td>
|
||||
<td>1 hour = 60 minutes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>minute</td>
|
||||
<td><code>min</code></td>
|
||||
<td>1 minute = 60 seconds</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>second</td>
|
||||
<td><code>sec</code></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</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>).
|
||||
</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>).
|
||||
</li>
|
||||
<li>
|
||||
Mimic the formatting shown in the test-cases (quantities sorted from largest unit to smallest and separated by comma+space; value and unit of each quantity separated by space).
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -6,12 +6,15 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Task:
|
||||
<p>Create a function, or show a built-in function, to count the number of non-overlapping occurrences of a substring inside a string.</p><p>The function should take two arguments:</p>
|
||||
the first argument being the string to search, and
|
||||
the second a substring to be searched for.
|
||||
<p>It should return an integer count.</p>
|
||||
<p>The matching should yield the highest number of non-overlapping matches.</p><p>In general, this essentially means matching from left-to-right or right-to-left.</p>
|
||||
Create a function, or show a built-in function, to count the number of non-overlapping occurrences of a substring inside a string.
|
||||
The function should take two arguments:
|
||||
<ul>
|
||||
<li>the first argument being the string to search, and</li>
|
||||
<li>the second a substring to be searched for.</li>
|
||||
</ul>
|
||||
It should return an integer count.
|
||||
The matching should yield the highest number of non-overlapping matches.
|
||||
In general, this essentially means matching from left-to-right or right-to-left.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -6,22 +6,27 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>There are four types of common coins in <a href="https://en.wikipedia.org/wiki/United_States" title="link: https://en.wikipedia.org/wiki/United_States">US</a> currency:</p>
|
||||
quarters (25 cents)
|
||||
dimes (10 cents)
|
||||
nickels (5 cents), and
|
||||
pennies (1 cent)
|
||||
There are four types of common coins in <a href="https://en.wikipedia.org/wiki/United_States" title="link: https://en.wikipedia.org/wiki/United_States">US</a> currency:
|
||||
<ul>
|
||||
<li>quarters (25 cents)</li>
|
||||
<li>dimes (10 cents)</li>
|
||||
<li>nickels (5 cents), and</li>
|
||||
<li>pennies (1 cent)</li>
|
||||
</ul>
|
||||
<p>There are six ways to make change for 15 cents:</p>
|
||||
A dime and a nickel
|
||||
A dime and 5 pennies
|
||||
3 nickels
|
||||
2 nickels and 5 pennies
|
||||
A nickel and 10 pennies
|
||||
15 pennies
|
||||
Task:
|
||||
<p>Implement a function to determine how many ways there are to make change for a dollar using these common coins? (1 dollar = 100 cents).</p>
|
||||
Reference:
|
||||
<a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_Temp_52" title="link: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_Temp_52">an algorithm from MIT Press</a>.
|
||||
<ul>
|
||||
<li>A dime and a nickel</li>
|
||||
<li>A dime and 5 pennies</li>
|
||||
<li>3 nickels</li>
|
||||
<li>2 nickels and 5 pennies</li>
|
||||
<li>A nickel and 10 pennies</li>
|
||||
<li>15 pennies</li>
|
||||
</ul>
|
||||
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="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_Temp_52" title="link: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_Temp_52">an algorithm from MIT Press</a>.</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -6,25 +6,30 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>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.</p>
|
||||
<p>Given</p>
|
||||
<p><big></p>
|
||||
<p> $\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.$</p>
|
||||
</big><p>which in matrix format is</p><p><big></p>
|
||||
<p> $\begin{bmatrix} a_1 & b_1 & c_1 \\ a_2 & b_2 & c_2 \\ a_3 & b_3 & c_3 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \end{bmatrix}=\begin{bmatrix} {\color{red}d_1} \\ {\color{red}d_2} \\ {\color{red}d_3} \end{bmatrix}.$</p>
|
||||
</big><p>Then the values of $x, y$ and $z$ can be found as follows:</p><p><big></p>
|
||||
<p>$x = \frac{\begin{vmatrix} {\color{red}d_1} & b_1 & c_1 \\ {\color{red}d_2} & b_2 & c_2 \\ {\color{red}d_3} & b_3 & c_3 \end{vmatrix} } { \begin{vmatrix} a_1 & b_1 & c_1 \\ a_2 & b_2 & c_2 \\ a_3 & b_3 & c_3 \end{vmatrix}}, \quad y = \frac {\begin{vmatrix} a_1 & {\color{red}d_1} & c_1 \\ a_2 & {\color{red}d_2} & c_2 \\ a_3 & {\color{red}d_3} & c_3 \end{vmatrix}} {\begin{vmatrix} a_1 & b_1 & c_1 \\ a_2 & b_2 & c_2 \\ a_3 & b_3 & c_3 \end{vmatrix}}, \text{ and }z = \frac { \begin{vmatrix} a_1 & b_1 & {\color{red}d_1} \\ a_2 & b_2 & {\color{red}d_2} \\ a_3 & b_3 & {\color{red}d_3} \end{vmatrix}} {\begin{vmatrix} a_1 & b_1 & c_1 \\ a_2 & b_2 & c_2 \\ a_3 & b_3 & c_3 \end{vmatrix} }.$</p>
|
||||
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.
|
||||
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.$
|
||||
</big>
|
||||
Task
|
||||
<p>Given the following system of equations:</p><p><big>
|
||||
$\begin{cases}
|
||||
2w-x+5y+z=-3 \\
|
||||
3w+2x+2y-6z=-32 \\
|
||||
w+3x+3y-z=-47 \\
|
||||
5w-2x-3y+3z=49 \\
|
||||
\end{cases}$
|
||||
</big></p>
|
||||
<p>solve for <big>$w$, $x$, $y$</big> and <big>$z$</big>, using Cramer's rule.</p>
|
||||
which in matrix format is
|
||||
<big>
|
||||
$\begin{bmatrix} a_1 & b_1 & c_1 \\ a_2 & b_2 & c_2 \\ a_3 & b_3 & c_3 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \end{bmatrix}=\begin{bmatrix} {\color{red}d_1} \\ {\color{red}d_2} \\ {\color{red}d_3} \end{bmatrix}.$
|
||||
</big>
|
||||
Then the values of $x, y$ and $z$ can be found as follows:
|
||||
<big>
|
||||
$x = \frac{\begin{vmatrix} {\color{red}d_1} & b_1 & c_1 \\ {\color{red}d_2} & b_2 & c_2 \\ {\color{red}d_3} & b_3 & c_3 \end{vmatrix} } { \begin{vmatrix} a_1 & b_1 & c_1 \\ a_2 & b_2 & c_2 \\ a_3 & b_3 & c_3 \end{vmatrix}}, \quad y = \frac {\begin{vmatrix} a_1 & {\color{red}d_1} & c_1 \\ a_2 & {\color{red}d_2} & c_2 \\ a_3 & {\color{red}d_3} & c_3 \end{vmatrix}} {\begin{vmatrix} a_1 & b_1 & c_1 \\ a_2 & b_2 & c_2 \\ a_3 & b_3 & c_3 \end{vmatrix}}, \text{ and }z = \frac { \begin{vmatrix} a_1 & b_1 & {\color{red}d_1} \\ a_2 & b_2 & {\color{red}d_2} \\ a_3 & b_3 & {\color{red}d_3} \end{vmatrix}} {\begin{vmatrix} a_1 & b_1 & c_1 \\ a_2 & b_2 & c_2 \\ a_3 & b_3 & c_3 \end{vmatrix} }.$
|
||||
</big>
|
||||
<b>Task</b>
|
||||
Given the following system of equations:
|
||||
<big>
|
||||
$\begin{cases}
|
||||
2w-x+5y+z=-3 \\
|
||||
3w+2x+2y-6z=-32 \\
|
||||
w+3x+3y-z=-47 \\
|
||||
5w-2x-3y+3z=49 \\
|
||||
\end{cases}$
|
||||
</big>
|
||||
solve for <big>$w$, $x$, $y$</big> and <big>$z$</big>, using Cramer's rule.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -7,7 +7,11 @@ challengeType: 5
|
||||
## Description
|
||||
<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.
|
||||
<a href="http://rosettacode.org/wiki/file:rect-cut.svg">file:rect-cut.svg</a>
|
||||
<div style="width: 100%; text-align: center;">
|
||||
<a href="http://rosettacode.org/wiki/file:rect-cut.svg" target="_blank">
|
||||
<img src="https://rosettacode.org/mw/images/5/55/Rect-cut.svg" width="520" height="170" alt="Picture of cut rectangles">
|
||||
</a>
|
||||
</div>
|
||||
Write a function that calculates the number of different ways to cut an <i>m</i> × <i>n</i> rectangle.
|
||||
</section>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user