fix(challenges): Went back and fixed a missing A problem. Fixed C problems.

This commit is contained in:
Kris Koishigawa
2019-02-25 13:36:09 +09:00
committed by mrugesh
parent f9f4048258
commit d024b96a92
14 changed files with 238 additions and 190 deletions

View File

@ -6,9 +6,10 @@ challengeType: 5
## Description ## Description
<section id='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> 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>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> The <i>root mean square</i> is also known by its initials RMS (or rms), and as the <b>quadratic mean</b>.
<p><big>$$x_{\mathrm{rms}} = \sqrt {{{x_1}^2 + {x_2}^2 + \cdots + {x_n}^2} \over n}. $$</big></p> 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> </section>
## Instructions ## Instructions

View File

@ -6,12 +6,14 @@ challengeType: 5
## Description ## Description
<section id='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> <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?</blockquote> <blockquote>
<p> - Babbage, letter to Lord Bowden, 1837; see Hollingdale and Tootill, <i>Electronic Computers</i>, second edition, 1970, p. 125.</p> What is the smallest positive integer whose square ends in the digits 269,696?
<p>He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain.</p> <footer>Babbage, letter to Lord Bowden, 1837; see Hollingdale and Tootill, <i>Electronic Computers</i>, second edition, 1970, p. 125.</footer>
<p>The task is to find out if Babbage had the right answer.</p> </blockquote>
<p>Implement a function to return the lowest integer that satisfies the Babbage problem. If Babbage was right, return Babbage's number.</p> 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> </section>
## Instructions ## Instructions

View File

@ -6,15 +6,17 @@ challengeType: 5
## Description ## Description
<section id='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: Examples:
<p class='rosetta__paragraph'>(empty) true</p> <pre>
<p class='rosetta__paragraph'><code>[]</code> true</p> (empty) true
<p class='rosetta__paragraph'><code>][</code> false</p> <code>[]</code> true
<p class='rosetta__paragraph'><code>[][]</code> true</p> <code>][</code> false
<p class='rosetta__paragraph'><code>][][</code> false</p> <code>[][]</code> true
<p class='rosetta__paragraph'><code>[]][[]</code> false</p> <code>][][</code> false
<p class='rosetta__paragraph'><code>[[[[]]]]</code> true</p> <code>[]][[]</code> false
<code>[[[[]]]]</code> true
</pre>
</section> </section>
## Instructions ## Instructions

View File

@ -6,18 +6,23 @@ challengeType: 5
## Description ## Description
<section id='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> Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions: <b>Exceptions:</b>
A radius of zero should be treated as never describing circles (except in the case where the points are coincident). <ul>
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>A radius of zero should be treated as never describing circles (except in the case where the points are coincident).</li>
If the points form a diameter then return a single circle. <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>
If the points are too far apart then no circles can be drawn.Task: <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. 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: <b>For edge cases, return the following:</b>
If points are on the diameter, return one point. If the radius is also zero however, return <code>"Radius Zero"</code>. <ul>
If points are coincident, return <code>"Coincident point. Infinite solutions"</code>. <li>If points are on the diameter, return one point. If the radius is also zero however, return <code>"Radius Zero"</code>.</li>
If points are farther apart than the diameter, return <code>"No intersection. Points further apart than circle diameter"</code>. <li>If points are coincident, return <code>"Coincident point. Infinite solutions"</code>.</li>
Sample inputs: <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> <pre>
p1 p2 r p1 p2 r
0.1234, 0.9876 0.8765, 0.2345 2.0 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.8765, 0.2345 0.5
0.1234, 0.9876 0.1234, 0.9876 0.0 0.1234, 0.9876 0.1234, 0.9876 0.0
</pre> </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 <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> </section>

View File

@ -6,34 +6,34 @@ challengeType: 5
## Description ## Description
<section id='description'> <section id='description'>
Task: 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.
<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> 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> <pre>
bruteForceClosestPair of P(1), P(2), ... P(N) <b>bruteForceClosestPair</b> of P(1), P(2), ... P(N)
if N &lt; 2 then <b>if</b> N < 2 <b>then</b>
return <b>return</b>
else <b>else</b>
minDistance ← |P(1) - P(2)| minDistance ← |P(1) - P(2)|
minPoints ← { P(1), P(2) } minPoints ← { P(1), P(2) }
foreach i ∈ [1, N-1] <b>foreach</b> i ∈ [1, N-1]
foreach j ∈ [i+1, N] <b>foreach</b> j ∈ [i+1, N]
if |P(i) - P(j)| < minDistance then <b>if</b> |P(i) - P(j)| < minDistance <b>then</b>
minDistance ← |P(i) - P(j)| minDistance ← |P(i) - P(j)|
minPoints ← { P(i), P(j) } minPoints ← { P(i), P(j) }
endif <b>endif</b>
endfor <b>endfor</b>
endfor <b>endfor</b>
return minDistance, minPoints <b>return</b> minDistance, minPoints
endif <b>endif</b>
</pre> </pre>
<p>A better algorithm is based on the recursive divide&amp;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> <pre>
closestPair of (xP, yP) <b>closestPair</b> of (xP, yP)
where xP is P(1) .. P(N) sorted by x coordinate, and where xP is P(1) .. P(N) sorted by x coordinate, and
yP is P(1) .. P(N) sorted by y coordinate (ascending order) yP is P(1) .. P(N) sorted by y coordinate (ascending order)
if N ≤ 3 then <b>if</b> N ≤ 3 <b>then</b>
return closest points of xP using brute-force algorithm <b>return</b> closest points of xP using brute-force algorithm
else <b>else</b>
xL ← points of xP from 1 to ⌈N/2⌉ xL ← points of xP from 1 to ⌈N/2⌉
xR ← points of xP from ⌈N/2⌉+1 to N xR ← points of xP from ⌈N/2⌉+1 to N
xm ← xP(⌈N/2⌉)<sub>x</sub> xm ← xP(⌈N/2⌉)<sub>x</sub>
@ -42,31 +42,33 @@ else
(dL, pairL) ← closestPair of (xL, yL) (dL, pairL) ← closestPair of (xL, yL)
(dR, pairR) ← closestPair of (xR, yR) (dR, pairR) ← closestPair of (xR, yR)
(dmin, pairMin) ← (dR, pairR) (dmin, pairMin) ← (dR, pairR)
if dL &lt; dR then <b>if</b> dL < dR <b>then</b>
(dmin, pairMin) ← (dL, pairL) (dmin, pairMin) ← (dL, pairL)
endif <b>endif</b>
yS ← { p ∈ yP : |xm - p<sub>x</sub>| &lt; dmin } yS ← { p ∈ yP : |xm - p<sub>x</sub>| &lt; dmin }
nS ← number of points in yS nS ← number of points in yS
(closest, closestPair) ← (dmin, pairMin) (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 k ← i + 1
while k ≤ nS and yS(k)<sub>y</sub> - yS(i)<sub>y</sub> &lt; dmin <b>while</b> k ≤ nS <b>and</b> yS(k)<sub>y</sub> - yS(i)<sub>y</sub> < dmin
if |yS(k) - yS(i)| &lt; closest then <b>if</b> |yS(k) - yS(i)| < closest <b>then</b>
(closest, closestPair) ← (|yS(k) - yS(i)|, {yS(k), yS(i)}) (closest, closestPair) ← (|yS(k) - yS(i)|, {yS(k), yS(i)})
endif <b>endif</b>
k ← k + 1 k ← k + 1
endwhile <b>endwhile</b>
endfor <b>endfor</b>
return closest, closestPair <b>return</b> closest, closestPair
endif <b>endif</b>
</pre> </pre>
References and further readings: 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).
<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> <b>References and further readings:</b>
<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> <ul>
<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><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>
<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><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>
<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><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>
<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> <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> </section>
## Instructions ## Instructions

View File

@ -6,10 +6,9 @@ challengeType: 5
## Description ## Description
<section id='description'> <section id='description'>
Task: 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).
<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> <b>Example:</b>
Example: <big><b>3</b></big> comb <big><b>5</b></big> is:
<p><big>3</big> comb <big> 5 </big>is:</p>
<pre> <pre>
0 1 2 0 1 2
0 1 3 0 1 3

View File

@ -6,18 +6,22 @@ challengeType: 5
## Description ## Description
<section id='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> 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>.
Task:<p>Write a function to generate a string output which is the concatenation of input words from a list/sequence where:</p> Write a function to generate a string output which is the concatenation of input words from a list/sequence where:
An input of no words produces the output string of just the two brace characters "{}". <ol>
An input of just one word, e.g. ["ABC"], produces the output string of the word inside the two braces, e.g. "{ABC}". <li>An input of no words produces the output string of just the two brace characters "{}".</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>An input of just one word, e.g. ["ABC"], produces the output string of the word inside the two braces, e.g. "{ABC}".</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>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>
<p>Test your function with the following series of inputs showing your output here on this page:</p> <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>
[] # (No input words). </ol>
["ABC"] Test your function with the following series of inputs showing your output here on this page:
["ABC", "DEF"] <ul>
["ABC", "DEF", "G", "H"] <li>[] # (No input words).</li>
<p>Note: Assume words are non-empty strings of uppercase characters for this task.</p> <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> </section>
## Instructions ## Instructions

View File

@ -6,8 +6,11 @@ challengeType: 5
## Description ## Description
<section id='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 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:
test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) <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> </section>
## Instructions ## Instructions

View File

@ -6,11 +6,13 @@ challengeType: 5
## Description ## Description
<section id='description'> <section id='description'>
Task: Implement a function which:
<p>Implement a function which:</p> <ul>
takes a positive integer representing a duration in seconds as input (e.g., <code>100</code>), and <li>takes a positive integer representing a duration in seconds as input (e.g., <code>100</code>), and</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>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>
<p>Demonstrate that it passes the following three test-cases:</p><p style="font-size:115%; margin:1em 0 0 0">Test Cases</p> </ul>
Demonstrate that it passes the following three test-cases:
<div style="font-size:115%; font-weight: bold;">Test Cases</div>
<table> <table>
<tbody> <tbody>
<tr> <tr>
@ -31,7 +33,9 @@ returns a string which shows the same duration decomposed into weeks, days, hour
</tr> </tr>
</tbody> </tbody>
</table> </table>
<p style="font-size:115%; margin:1em 0 0 0">Details</p> <div style="font-size:115%; font-weight: bold;">Details</div>
<ul>
<li>
The following five units should be used: The following five units should be used:
<table> <table>
<tbody> <tbody>
@ -67,8 +71,17 @@ The following five units should be used:
</tr> </tr>
</tbody> </tbody>
</table> </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). </li>
<p><hr style="margin:1em 0;"/></p> <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> </section>
## Instructions ## Instructions

View File

@ -6,12 +6,15 @@ challengeType: 5
## Description ## Description
<section id='description'> <section id='description'>
Task: Create a function, or show a built-in function, to count the number of non-overlapping occurrences of a substring inside a string.
<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 function should take two arguments:
the first argument being the string to search, and <ul>
the second a substring to be searched for. <li>the first argument being the string to search, and</li>
<p>It should return an integer count.</p> <li>the second a substring to be searched for.</li>
<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> </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> </section>
## Instructions ## Instructions

View File

@ -6,22 +6,27 @@ challengeType: 5
## Description ## Description
<section id='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> 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:
quarters (25 cents) <ul>
dimes (10 cents) <li>quarters (25 cents)</li>
nickels (5 cents), and <li>dimes (10 cents)</li>
pennies (1 cent) <li>nickels (5 cents), and</li>
<li>pennies (1 cent)</li>
</ul>
<p>There are six ways to make change for 15 cents:</p> <p>There are six ways to make change for 15 cents:</p>
A dime and a nickel <ul>
A dime and 5 pennies <li>A dime and a nickel</li>
3 nickels <li>A dime and 5 pennies</li>
2 nickels and 5 pennies <li>3 nickels</li>
A nickel and 10 pennies <li>2 nickels and 5 pennies</li>
15 pennies <li>A nickel and 10 pennies</li>
Task: <li>15 pennies</li>
<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> </ul>
Reference: Implement a function to determine how many ways there are to make change for a dollar using these common coins? (1 dollar = 100 cents)
<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>. <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> </section>
## Instructions ## Instructions

View File

@ -6,25 +6,30 @@ challengeType: 5
## Description ## Description
<section id='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> 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>Given</p> Given
<p><big></p> <big>
<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> $\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><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>
</big> </big>
Task which in matrix format is
<p>Given the following system of equations:</p><p><big> <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} $\begin{cases}
2w-x+5y+z=-3 \\ 2w-x+5y+z=-3 \\
3w+2x+2y-6z=-32 \\ 3w+2x+2y-6z=-32 \\
w+3x+3y-z=-47 \\ w+3x+3y-z=-47 \\
5w-2x-3y+3z=49 \\ 5w-2x-3y+3z=49 \\
\end{cases}$ \end{cases}$
</big></p> </big>
<p>solve for <big>$w$, $x$, $y$</big> and <big>$z$</big>, using Cramer's rule.</p> solve for <big>$w$, $x$, $y$</big> and <big>$z$</big>, using Cramer's rule.
</section> </section>
## Instructions ## Instructions

View File

@ -7,7 +7,11 @@ challengeType: 5
## Description ## Description
<section id='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 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. Write a function that calculates the number of different ways to cut an <i>m</i> × <i>n</i> rectangle.
</section> </section>