# Khan/khan-exercises

### Subversion checkout URL

You can clone with HTTPS or Subversion.

Fetching contributors…

Cannot retrieve contributors at this time

107 lines (105 sloc) 4.929 kb
 Triangle Inequality Theorem
randomTriangleWithSides() rand( 3 ) MAIN[ 1 ][ HIDDEN ] MAIN[ 1 ].slice( 0, HIDDEN ).concat( MAIN[ 1 ].slice( HIDDEN + 1 ) ) ( parseFloat( KNOWN[ 0 ] ) + parseFloat( KNOWN[ 1 ] ) ).toFixed( 1 ) Math.abs( KNOWN[ 0 ] - KNOWN[ 1 ] ).toFixed( 1 )
What is the range of possible sizes for side x?
init({ range: [ [ -1, 10 ], [ -7.5, 1 ] ] }) var tr = new Triangle( [ 3, -6.5 ], MAIN[ 0 ], 5, { "c" : HIDDEN !== 2 ? MAIN[ 1 ][ 2 ] : "x" , "a" : HIDDEN !== 0 ? MAIN[ 1 ][ 0 ] : "x" , "b" : HIDDEN !== 1 ? MAIN[ 1 ][ 1 ] : "x" } ); tr.boxOut( [ [ [ -1, -10 ], [ -1, 10 ] ] ], [ 1, 0 ] ); tr.boxOut( [ [ [ 10, -10 ], [ 10, 10 ] ] ], [ -1, 0 ] ); tr.draw(); tr.drawLabels();

Maximum = MAX

Minimum = MIN

Triangle inequality theorem states that a side cannot be larger than the sum of the other two sides.

Therefore the the third side cannot be larger than KNOWN[ 0 ] + KNOWN[ 1 ] = MAX

By the same theorem, the side can also not be smaller than the difference between the two sides.

Therefore the third side cannot be smaller than | KNOWN[ 0 ] - KNOWN[ 1 ] | = MIN

randomTriangleWithSides() ( randRange( 0, 1 ) === 0 )
Can this triangle exist?
init({ range: [ [-1, 10 ], [ -7.5, 1 ] ] }) if( !POSSIBLE ){ var side = randRange( 0, 2 ); var sideValue = ( parseFloat( MAIN[ 1 ][ ( side + 1 ) % 3 ] ) + parseFloat( MAIN[ 1 ][ ( side + 2 ) % 3 ] ) + randRange( 1, 3 ) ).toFixed( 1 ); MAIN[ 1 ][ side ] = sideValue; } var tr = new Triangle( [ 3, -6.9 ], MAIN[ 0 ], 5, { "c" : MAIN[ 1 ][ 2 ], "a" : MAIN[ 1 ][ 0 ] , "b" : MAIN[ 1 ][ 1 ] } ); tr.boxOut( [ [ [ -1, -10 ], [ -1, 10 ] ] ], [ 1, 0 ] ); tr.boxOut( [ [ [ 10, -10 ], [ 10, 10 ] ] ], [ -1, 0 ] ); tr.draw(); tr.drawLabels();
POSSIBLE ? "Yes" : "No"
• Yes
• No

Triangle inequality theorem states that a side must be smaller than the sum of the other two sides.

Lets check for all three sides:

MAIN[ 1 ][ i ] + MAIN[ 1 ][ ( i + 1 ) % 3 ] = ( parseFloat( MAIN[ 1 ][ i ] ) + parseFloat( MAIN[ 1 ][ ( i + 1 ) % 3 ] ) ).toFixed( 1 )

MAIN[ 1 ][ ( i + 2 ) % 3 ] is not smaller than ( parseFloat( MAIN[ 1 ][ i ] ) + parseFloat( MAIN[ 1 ][ ( i + 1 ) % 3 ] ) ).toFixed( 1 ) so the theorem does not holdholds.

All three sides conform to the inequality theorem, so this triangle can exist.

Not all three sides conform to the inequality theorem, so this triangle cannot exist.

Something went wrong with that request. Please try again.