# publicKhan/khan-exercises

### Subversion checkout URL

You can clone with HTTPS or Subversion.

Older
100644 112 lines (111 sloc) 6.555 kb
 ``` b03482a7 » igorT ``` 2011-09-02 New exercise for triangle inequalities 1 2 3 ``` 4e4cb9b1 » beneater ``` 2012-04-10 lint: tabs->spaces and jQuery->\$ for exercises 4 5 Triangle Inequality Theorem 6 7 ``` 064281ea » beneater ``` 2012-09-19 Fix up exercises that are too wide for tutorials 22 ``` b03482a7 » igorT ``` 2011-09-02 New exercise for triangle inequalities 27 28 ``` 4e4cb9b1 » beneater ``` 2012-04-10 lint: tabs->spaces and jQuery->\$ for exercises 29
30
31 randomTriangleWithSides() 32 rand( 3 ) 33 MAIN[ 1 ][ HIDDEN ] 34 MAIN[ 1 ].slice( 0, HIDDEN ).concat( MAIN[ 1 ].slice( HIDDEN + 1 ) ) 35 roundTo( 1, parseFloat( KNOWN[ 0 ] ) + parseFloat( KNOWN[ 1 ] ) ) 36 roundTo( 1, abs( KNOWN[ 0 ] - KNOWN[ 1 ] ) ) 37
``` b03482a7 » igorT ``` 2011-09-02 New exercise for triangle inequalities 38 ``` 4e4cb9b1 » beneater ``` 2012-04-10 lint: tabs->spaces and jQuery->\$ for exercises 39
40
41
42 What is the range of possible sizes for side x? 43
44
45
46 init({ 47 range: [ [ -1, 10 ], [ -7.5, 1 ] ] 48 }) 49 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" ] } ); 50 tr.boxOut( [ [ [ -1, -10 ], [ -1, 10 ] ] ], [ 1, 0 ] ); 51 tr.boxOut( [ [ [ 10, -10 ], [ 10, 10 ] ] ], [ -1, 0 ] ); 52 tr.draw(); 53 tr.drawLabels(); 54
55
56
57

MIN < x < MAX

58 two exact decimals, like 0.75 59
60
61

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

62

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

63

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

64

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

65

So MIN < x < MAX

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

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

100

Let's check for all three sides:

101
102

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

103

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.

104
105

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

106

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

107
108
109
110
``` b03482a7 » igorT ``` 2011-09-02 New exercise for triangle inequalities 111 112
Something went wrong with that request. Please try again.