Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
triangle inequality exercise finished
  • Loading branch information
igorT committed Sep 13, 2011
1 parent bf5608a commit 26b0aff
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions exercises/triangle_inequality.html
Expand Up @@ -29,13 +29,12 @@
<var id="KNOWN">MAIN[ 1 ].slice( 0, HIDDEN ).concat( MAIN[ 1 ].slice( HIDDEN + 1 ) )</var>
<var id="MAX">parseFloat( KNOWN[ 0 ] ) + parseFloat( KNOWN[ 1 ] )</var>
<var id="MIN">Math.abs( KNOWN[ 0 ] - KNOWN[ 1 ] ).toFixed( 1 )</var>

</div>

<div class="problems">
<div id="range">
<div class="problem">
What is the range of sizes for side x?
What is the range of possible sizes for side x?
</div>
<div class="question">
<div class="graphie">
Expand All @@ -50,32 +49,51 @@
<div class="solution" data-type="multiple">
<p>Maximum = <span class="sol"><var>MAX</var></span></p>
<p>Minimum = <span class="sol"><var>MIN</var></span></p>

</div>
<div class="hints">
<p>Triangle inequality theorem states that a side cannot be larger than the sum of the other two sides.</p>
<p>Therefore the largest the third side can be is <code><var>KNOWN[ 0 ]</var> + <var>KNOWN[ 1 ]</var> = <var>MAX</var></code></p>
<p>By the same theorem, the side can also not be smaller than the difference between the two sides<p>
<p>Therefore the smallest the third side can be is <code>| <var>KNOWN[ 0 ]</var> - <var>KNOWN[ 1 ]</var> | = <var>MIN</var></code></p>¬
<p>Therefore the the third side cannot be larger than <code><var>KNOWN[ 0 ]</var> + <var>KNOWN[ 1 ]</var> = <var>MAX</var></code></p>
<p>By the same theorem, the side can also not be smaller than the difference between the two sides.<p>
<p>Therefore the third side cannot be smaller than <code>| <var>KNOWN[ 0 ]</var> - <var>KNOWN[ 1 ]</var> | = <var>MIN</var></code></p>
</div>
</div>
<div id="range">
<div class="vars">
<var id="MAIN">randomTriangleWithSides()</var>
<var id="POSSIBLE">( randRange( 0, 1 ) === 0 )</var>
</div>
<div class="problem">
NOT DONE YET Can this triangle exist?
Can this triangle exist?
</div>
<div class="question">
<div class="graphie">
init({
range: [ [-1, 10 ], [ -14, 2.5 ] ]
range: [ [-1, 10 ], [ -7, 0 ] ]
})
var tr = new Triangle( [ 3, -4], MAIN, [ 1, 1, 1], 5, { "c" : "ba", "a" : "cb" , "b" : "ac" } );
if( !POSSIBLE ){
var side = randRange( 0, 2 );
var sideValue = parseFloat( MAIN[ 1 ][ ( side + 1 ) % 3 ] ) + parseFloat( MAIN[ 1 ][ ( side + 2 ) % 3 ] ) + randRange( 1, 3 );
MAIN[ 1 ][ side ] = sideValue;
}
var tr = new Triangle( [ 3, -5 ], MAIN[ 0 ], [ 1, 1, 1], 5, { "c" : MAIN[ 1 ][ 2 ], "a" : MAIN[ 1 ][ 0 ] , "b" : MAIN[ 1 ][ 1 ] } );
tr.draw();
tr.drawLabels();
</div>
</div>
<div class="solution">5</div>
<div class="solution"><var>POSSIBLE ? "Yes" : "No"</var></div>
<ul class="choices" data-category="true">
<li>Yes</li>
<li>No</li>
</ul>
<div class="hints">
<p><b>SOH</b> CAH TOA</p>
<p>Triangle inequality theorem states that a side must be smaller than the sum of the other two sides.</p>
<p>Lets check for all three sides:</p>
<div data-each="MAIN[ 1 ] as i, v">
<p><code><var>MAIN[ 1 ][ i ]</var> + <var>MAIN[ 1 ][ ( i + 1 ) % 3 ]</var> = <var>( parseFloat( MAIN[ 1 ][ i ] ) + parseFloat( MAIN[ 1 ][ ( i + 1 ) % 3 ] ) ).toFixed( 1 )</var></code></p>
<p><code><var>MAIN[ 1 ][ ( i + 2 ) % 3 ]</var></code> is <span data-if="parseFloat( MAIN[ 1 ][ ( i + 2 ) % 3 ] ) >= ( parseFloat( MAIN[ 1 ][ i ] ) + parseFloat( MAIN[ 1 ][ ( i + 1 ) % 3 ] ) ) ">not</span> smaller than <var>( parseFloat( MAIN[ 1 ][ i ] ) + parseFloat( MAIN[ 1 ][ ( i + 1 ) % 3 ] ) ).toFixed( 1 )</var></code> so the theorem <span data-if="parseFloat( MAIN[ 1 ][ ( i + 2 ) % 3 ] ) >= ( parseFloat( MAIN[ 1 ][ i ] ) + parseFloat( MAIN[ 1 ][ ( i + 1 ) % 3 ] ) )">does not hold</span><span data-else>holds</span>.</p>
</div>
<p data-if="POSSIBLE">All three sides conform to the inequality theorem, so this triangle can exist.</p>
<p data-else>Not all three sides conform to the inequality theorem, so this triangle cannot exist.</p>
</div>
</div>
</div>
Expand Down

0 comments on commit 26b0aff

Please sign in to comment.