# Khan/khan-exercises

1 parent c6a7e9a commit 9e59905fd09c47569ac97e1f21d667c626145cd1 marcia committed Jul 13, 2011
Showing with 155 additions and 100 deletions.
2. +108 −100 exercises/multiplying_decimals.html
 @@ -0,0 +1,47 @@ + + + + Adding and Subtracting Fractions + + + +
+
+ randRangeNonZero( -9, 9 ) + randRangeNonZero( -9, 9 ) + randRangeExclude( 2, 9, [ N1, -N1 ] ) + randRangeExclude( 2, 9, [ N2, -N2 ] ) + getLCM( D1, D2 ) + LCM / D1 + LCM / D2 +
+ +
+
+

fraction( N1, D1 ) + fraction( N2, D2 ) = ?

+
N1 / D1 + N2 / D2
+
+
+ +
+

First, we need to find a common denominator. The least common multiple of D1 and D2 is the smallest possible common denominator.

+

LCM( D1, D2 ) = LCM

+

Now, we need to change both fractions to have a denominator of LCM.

+

\begin{align*}fraction( N1, D1 )\cdot fraction( F1, F1 ) &= fraction( N1 * F1, LCM )\end{align*}

+

\begin{align*}fraction( N2, D2 )\cdot fraction( F2, F2 ) &= fraction( N2 * F2, LCM )\end{align*}

+
+

So, the problem becomes:

+

fraction( N1 * F1, LCM ) + fraction( N2 * F2, LCM ) = ?

+
+
+

+

fraction( F1 * N1 + F2 * N2, LCM)

+
+
+

Simplify.

+

fractionReduce( F1 * N1 + F2 * N2, LCM )

+
+
+
+ +
208 exercises/multiplying_decimals.html
 @@ -1,116 +1,124 @@ - + - Multiplying decimals + Multiplying Decimals
-
- rand(3) - rand(3) - max( A_SHIFT, B_SHIFT) - intWithoutZero(3) / pow( 10, A_SHIFT) - intWithoutZero(3) / pow( 10, B_SHIFT) - digits( round( A * pow( 10, A_SHIFT ))) - digits( round( B * pow( 10, B_SHIFT ))) - createLongMultiplicationTable( A_ARRAY, B_ARRAY[0]) - TABLE.digits - TABLE.carry - createLongMultiplicationTable( A_ARRAY, B_ARRAY[1]) - TABLE2.digits - TABLE2.carry - [0].concat(DIGITS2) - createLongMultiplicationTable( A_ARRAY, B_ARRAY[2]) - TABLE3.digits - TABLE3.carry - [0,0].concat(DIGITS3) - createLongAdditionTable( DIGITS, EX_DIGITS2, EX_DIGITS3) - round(A*B*pow(10, A_SHIFT+B_SHIFT)) / pow(10, A_SHIFT+B_SHIFT) +
+ randRange( 100, 999 ) + randRange( 100, 999 ) + 0 + SMALL_FACTOR * BIG_FACTOR + integerToDigits( PRODUCT ) + digits( SMALL_FACTOR ) + digits( BIG_FACTOR ) + [] + randRange( 1, 3 ) + randRange( 1, 3 )
-

A * B = ?

-
RESULT
+
+ init({ + range: [ [ -1 - PRODUCT_DIGITS.length, 3 ], [ -1 - SMALL_FACTOR_DIGITS.length, 3 ] ], + scale: [ 30, 45 ] + }); + + style({ + strokeWidth: 1 + }); + + drawDigits( SMALL_FACTOR_DIGITS.slice( 0 ).reverse(), 1 - SMALL_FACTOR_DIGITS.length, 1 ); + drawDigits( BIG_FACTOR_DIGITS.slice( 0 ).reverse(), 1 - BIG_FACTOR_DIGITS.length, 2 ); + path( [ [ -1 - PRODUCT_DIGITS.length, 0.5 ], [ 1, 0.5 ] ] ); + label( [ -BIG_FACTOR_DIGITS.length, 1 ] ,"\\huge{\\times\\vphantom{0}}" ); + style({ + fill: "black" + }, function() { + ellipse( [ -BIG_FACTOR_DECIMAL + 0.5, 1.8 ], [ 0.09, 0.06 ] ); + ellipse( [ -SMALL_FACTOR_DECIMAL + 0.5, 0.8 ], [ 0.09, 0.06 ] ); + }); +
+
PRODUCT * pow( 10, -(BIG_FACTOR_DECIMAL + SMALL_FACTOR_DECIMAL) )
-

A_ARRAY[0] * B_ARRAY[0] = A_ARRAY[0]*B_ARRAY[0]

-

carry = CARRY[1]

-

Write DIGITS[0] as the digit

-

A_ARRAY[1] * B_ARRAY[0] + CARRY[1] = A_ARRAY[1] * B_ARRAY[0] + CARRY[1]

-

A_ARRAY[1] * B_ARRAY[0] = A_ARRAY[1] * B_ARRAY[0]

-

carry = CARRY[2]

-

Write DIGITS[1] as the digit

-

A_ARRAY[2] * B_ARRAY[0] + CARRY[2] = A_ARRAY[2] * B_ARRAY[0] + CARRY[2]

-

A_ARRAY[2] * B_ARRAY[0] = A_ARRAY[2] * B_ARRAY[0]

-

Write DIGITS[3]DIGITS[2] as the digit

-

Result is DIGITS[3]DIGITS[2]DIGITS[1]DIGITS[0]

- -

Now do the same with the second digit of the multiplicand and write down 0 as the first digit

-

A_ARRAY[0] * B_ARRAY[1] = A_ARRAY[0]*B_ARRAY[1]

-

carry = CARRY2[1]

-

Write DIGITS2[0] as the digit

-

A_ARRAY[1] * B_ARRAY[1] + CARRY2[1] = A_ARRAY[1] * B_ARRAY[1] + CARRY2[1]

-

A_ARRAY[1] * B_ARRAY[1] = A_ARRAY[1] * B_ARRAY[1]

-

carry = CARRY2[2]

-

Write DIGITS2[1] as the digit

-

A_ARRAY[2] * B_ARRAY[1] + CARRY2[2] = A_ARRAY[2] * B_ARRAY[1] + CARRY2[2]

-

A_ARRAY[2] * B_ARRAY[1] = A_ARRAY[2] * B_ARRAY[1]

-

Write DIGITS2[3]DIGITS2[2] as the digit

-

Result is DIGITS2[3]DIGITS2[2]DIGITS2[1]DIGITS2[0]0

- -

Now do the same with the third digit of the multiplicand and write down two 0's

-

A_ARRAY[0] * B_ARRAY[2] = A_ARRAY[0]*B_ARRAY[2]

-

carry = CARRY3[1]

-

Write DIGITS3[0] as the digit

-

A_ARRAY[1] * B_ARRAY[2] + CARRY3[1] = A_ARRAY[1] * B_ARRAY[2] + CARRY3[1]

-

A_ARRAY[1] * B_ARRAY[2] = A_ARRAY[1] * B_ARRAY[2]

-

carry = CARRY3[2]

-

Write DIGITS3[1] as the digit

-

A_ARRAY[2] * B_ARRAY[2] + CARRY3[2] = A_ARRAY[2] * B_ARRAY[2] + CARRY3[2]

-

A_ARRAY[2] * B_ARRAY[2] = A_ARRAY[2] * B_ARRAY[2]

-

Write DIGITS3[3]DIGITS3[2] as the digit

-

Result is DIGITS3[3]DIGITS3[2]DIGITS3[1]DIGITS3[0]00

- -

-

DIGITS[0] + EX_DIGITS2[0] + EX_DIGITS3[0] = DIGITS[0] + EX_DIGITS2[0] + EX_DIGITS3[0]

-

- -

DIGITS[1] + EX_DIGITS2[1] + EX_DIGITS3[1] + ADDITION_TABLE[1] = DIGITS[1] + EX_DIGITS2[1] + EX_DIGITS3[0]+ ADDITION_TABLE[1]

-

DIGITS[1] + EX_DIGITS2[1] + EX_DIGITS3[1] = DIGITS[1] + EX_DIGITS2[1] +EX_DIGITS3[1]

-

- -

DIGITS[2] + EX_DIGITS2[2] + EX_DIGITS3[2] + ADDITION_TABLE[2] = DIGITS[2] + EX_DIGITS2[2] + EX_DIGITS3[2] + ADDITION_TABLE[2]

-

DIGITS[2] + EX_DIGITS2[2] + EX_DIGITS3[2] = DIGITS[2] + EX_DIGITS2[2] + EX_DIGITS3[2]

-

- - -

DIGITS[3] + EX_DIGITS2[3] + EX_DIGITS3[3] + ADDITION_TABLE[3] = DIGITS[3] + EX_DIGITS2[3] + EX_DIGITS3[3] + ADDITION_TABLE[3]

-

DIGITS[3] + EX_DIGITS2[3] + EX_DIGITS3[3] = DIGITS[3] + EX_DIGITS2[3] + EX_DIGITS3[3]

-

- -

-

EX_DIGITS2[3] + EX_DIGITS3[3] = EX_DIGITS2[3] + EX_DIGITS3[3]

-

- - -

-

EX_DIGITS2[4] + EX_DIGITS3[4] = EX_DIGITS2[4] + EX_DIGITS3[4]

-

-

-

pull down EX_DIGITS3[5]

- -

-

pull down EX_DIGITS3[5]EX_DIGITS3[4]

-

pull down EX_DIGITS3[5]

-

The sum is RESULT*pow(10, A_SHIFT+B_SHIFT)

-

The first multiplicand has A_SHIFT digits after the decimal.

-

The second multiplicand has B_SHIFT digits after the decimal.

-

A_SHIFT + B_SHIFT = A_SHIFT+B_SHIFT

-

Put the decimal point A_SHIFT+B_SHIFT to the left

-

Final result is:RESULT

+
+
+ while( HIGHLIGHTS.length ) { + HIGHLIGHTS.pop().remove(); + } + var bigDigit = bigDigit; + var bigIndex = bigIndex; + var smallIndex = smallIndex; + var smallDigit = smallDigit; + if ( bigIndex === 0 ) { + CARRY = 0; + } + var product = smallDigit * bigDigit + CARRY; + var ones = product % 10; + var currCarry = floor( product / 10 ); + HIGHLIGHTS = HIGHLIGHTS.concat( drawDigits( [ bigDigit ], -bigIndex, 2, "#6495ED" ) ); + HIGHLIGHTS = HIGHLIGHTS.concat( drawDigits( [ smallDigit ], -smallIndex, 1, "#FF00AF" ) ); + if ( CARRY ) { + HIGHLIGHTS = HIGHLIGHTS.concat( label( [ -bigIndex, 3 ], "\\color{#FFA500}{" + CARRY + "}", "below" ) ); + } + label( [ 2, -smallIndex * BIG_FACTOR_DIGITS.length - bigIndex + 2 ], + "\\color{#6495ED}{" + bigDigit + "}" + + "\\times" + + "\\color{#FF00AF}{" + smallDigit + "}" + + ( CARRY ? "+\\color{#FFA500}{" + CARRY + "}" : "" ) + + "=" + + "\\color{#28AE7B}{" + product + "}", "right" ); + + drawDigits( [ ones ], -smallIndex - bigIndex, -smallIndex ); + HIGHLIGHTS = HIGHLIGHTS.concat( drawDigits( [ ones ], -smallIndex - bigIndex, -smallIndex, "#28AE7B" ) ); + + if ( currCarry ) { + HIGHLIGHTS = HIGHLIGHTS.concat( label( [ -1 - bigIndex, 3 ], "\\color{#28AE7B}{" + currCarry + "}", "below" ) ); + if ( bigIndex === BIG_FACTOR_DIGITS.length - 1 ) { + drawDigits( [ currCarry ], -smallIndex - bigIndex - 1, -smallIndex ); + HIGHLIGHTS = HIGHLIGHTS.concat( drawDigits( [ currCarry ], -smallIndex - bigIndex - 1, -smallIndex, "#28AE7B" ) ); + } + } + CARRY = currCarry; +
+
+ +
+
+ while( HIGHLIGHTS.length ) { + HIGHLIGHTS.pop().remove(); + } + path( [ [ -1 - PRODUCT_DIGITS.length, 0.5 - SMALL_FACTOR_DIGITS.length ], [ 1, 0.5 - SMALL_FACTOR_DIGITS.length ] ] ); + label( [ -1 - PRODUCT_DIGITS.length, 1 - SMALL_FACTOR_DIGITS.length ] ,"\\huge{+\\vphantom{0}}" ); +
+
+ drawDigits( PRODUCT_DIGITS, 1 - PRODUCT_DIGITS.length, -SMALL_FACTOR_DIGITS.length ); +
+
+ label( [ -1 - PRODUCT_DIGITS.length, -SMALL_FACTOR_DIGITS.length * BIG_FACTOR_DIGITS.length + 2 ], + "\\text{The top number has " + plural( BIG_FACTOR_DECIMAL, "digit" ) + " to the right of the decimal.}", "right" ); + label( [ -1 - PRODUCT_DIGITS.length, -SMALL_FACTOR_DIGITS.length * BIG_FACTOR_DIGITS.length + 1 ], + "\\text{The bottom number has " + plural( SMALL_FACTOR_DECIMAL, "digit" ) + " to the right of the decimal.}", "right" ); + label( [ -1 - PRODUCT_DIGITS.length, -SMALL_FACTOR_DIGITS.length * BIG_FACTOR_DIGITS.length ], + "\\text{The product has " + BIG_FACTOR_DECIMAL + " + " + SMALL_FACTOR_DECIMAL + " = " + ( SMALL_FACTOR_DECIMAL + BIG_FACTOR_DECIMAL ) + + " digits to the right of the decimal.}", "right" ); + style({ + fill: "black" + }, function() { + ellipse( [ -SMALL_FACTOR_DECIMAL - BIG_FACTOR_DECIMAL + 0.5, -0.2 - SMALL_FACTOR_DIGITS.length ], [ 0.09, 0.06 ] ); + }); +
+
+
+ while( HIGHLIGHTS.length ) { + HIGHLIGHTS.pop().remove(); + } +