# Khan/khan-exercises

### Subversion checkout URL

You can clone with
or
.
Older
100644 108 lines (106 sloc) 6.515 kB
 b03482a New exercise for triangle inequalities igorT authored Sep 2, 2011 1 2 3 4e4cb9b lint: tabs->spaces and jQuery->\$ for exercises beneater authored Apr 10, 2012 4 5 Triangle Inequality Theorem 6 7 b03482a New exercise for triangle inequalities igorT authored Sep 2, 2011 22 23 4e4cb9b lint: tabs->spaces and jQuery->\$ for exercises beneater authored Apr 10, 2012 24
25
26 randomTriangleWithSides() 27 rand( 3 ) 28 MAIN[ 1 ][ HIDDEN ] 29 MAIN[ 1 ].slice( 0, HIDDEN ).concat( MAIN[ 1 ].slice( HIDDEN + 1 ) ) 30 roundTo( 1, parseFloat( KNOWN[ 0 ] ) + parseFloat( KNOWN[ 1 ] ) ) 31 roundTo( 1, abs( KNOWN[ 0 ] - KNOWN[ 1 ] ) ) 32
b03482a New exercise for triangle inequalities igorT authored Sep 2, 2011 33 4e4cb9b lint: tabs->spaces and jQuery->\$ for exercises beneater authored Apr 10, 2012 34
35
36
37 What is the range of possible sizes for side x? 38
39
40
41 init({ 42 range: [ [ -1, 10 ], [ -7.5, 1 ] ] 43 }) 44 var tr = new Triangle( [ 3, -6.5 ], MAIN[ 0 ], 5, { "sides" : [ HIDDEN !== 2 ? MAIN[ 1 ][ 2 ] : "x", HIDDEN !== 0 ? MAIN[ 1 ][ 0 ] : "x", HIDDEN !== 1 ? MAIN[ 1 ][ 1 ] : "x" ] } ); 45 tr.boxOut( [ [ [ -1, -10 ], [ -1, 10 ] ] ], [ 1, 0 ] ); 46 tr.boxOut( [ [ [ 10, -10 ], [ 10, 10 ] ] ], [ -1, 0 ] ); 47 tr.draw(); 48 tr.drawLabels(); 49
50
51
725121f Consolidate answer input box width CSS so it doesn't leak between exe… beneater authored Feb 21, 2013 52

MIN < x < MAX

4e4cb9b lint: tabs->spaces and jQuery->\$ for exercises beneater authored Apr 10, 2012 53 two exact decimals, like 0.75 54
55
56

The triangle inequality theorem states that any side of a triangle is always shorter than the sum of the other two sides.

57

Therefore the the third side must be less than KNOWN[ 0 ] + KNOWN[ 1 ] = MAX

58

By the same theorem, the third side must be also larger than the difference between the other two sides.

59

Therefore the third side must be larger than KNOWN[0] < KNOWN[1] ? KNOWN[1] : KNOWN[0] - KNOWN[0] < KNOWN[1] ? KNOWN[0] : KNOWN[1] = MIN

60

So MIN < x < MAX

61
62
63
64
65 randomTriangleWithSides() 66 ( randRange( 0, 1 ) === 0 ) 67
68
69 Can this triangle exist? 70
71
72
73 init({ 74 range: [ [-1, 10 ], [ -7.5, 1 ] ] 75 }) 76 if( !POSSIBLE ){ 77 var side = randRange( 0, 2 ); 78 var sideValue = ( parseFloat( MAIN[ 1 ][ ( side + 1 ) % 3 ] ) + parseFloat( MAIN[ 1 ][ ( side + 2 ) % 3 ] ) + randRange( 1, 3 ) ).toFixed( 1 ); 79 MAIN[ 1 ][ side ] = sideValue; 80 } 81 var tr = new Triangle( [ 3, -6.9 ], MAIN[ 0 ], 5, { "sides" : [ MAIN[ 1 ][ 2 ], MAIN[ 1 ][ 0 ], MAIN[ 1 ][ 1 ] ] } ); 82 tr.boxOut( [ [ [ -1, -10 ], [ -1, 10 ] ] ], [ 1, 0 ] ); 83 tr.boxOut( [ [ [ 10, -10 ], [ 10, 10 ] ] ], [ -1, 0 ] ); 84 tr.draw(); 85 tr.drawLabels(); 86
87
88
POSSIBLE ? "Yes" : "No"
89
90
• Yes
• 91
• No
• 92
93
94

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

95

Let's check for all three sides:

96
97

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

98

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.

99
100

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

101

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

102
103
104
105
b03482a New exercise for triangle inequalities igorT authored Sep 2, 2011 106 107
Something went wrong with that request. Please try again.