Khan/khan-exercises

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
274 lines (256 sloc) 12.9 KB
 The fundamental theorem of arithmetic
[2, 3, 5, 7, 11, 13] randFromArray([ 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30, 32, 33, 35, 36, 39, 40, 42, 44, 45, 48, 49, 50, 52, 54, 55, 56, 60, 63, 65, 66, 70, 72, 75, 77, 78, 80, 81, 84, 88, 90, 91, 96, 98, 99]) getPrimeFactorization(NUMBER) _.reduce(FACTORIZATION, function(exponents, base) { exponents[base] = exponents[base] + 1 || 1; return exponents; }, {}) _.reduce(_.values(EXPONENTS), function(hasExponents, num) { return hasExponents || num !== 1; }, false) _.map(EXPONENTS, function(num, prime) { return cardinalThrough20(num) + " <code>" + prime + "</code>" + (num === 1 ? "" : "s"); }) _.reduce(PRIMES, function(factors, prime) { if (EXPONENTS[prime] > 1) { factors.push(prime + "^" + EXPONENTS[prime]); } else if (EXPONENTS[prime] === 1) { factors.push(prime); } return factors; }, []).join("\\cdot") _.map(FACTORIZATION, function(factor, step){ var remain = NUMBER; _.each(FACTORIZATION.slice(0, step), function(n) { remain /= n; }) return remain; }) null

Find the prime factorization of NUMBER.

Use the arrows to change the exponent on each prime number below to see if you can find the prime factorization.

1

GRAPHIE.computeTotal()
if (guess === 1) { return ""; } return guess === NUMBER;
_.each(PRIMES, function(prime) { GRAPHIE.primes[prime].exponent = 0; }); _.each(getPrimeFactorization(guess), function(prime) { GRAPHIE.primes[prime].exponent += 1; }); _.each(PRIMES, function(prime) { GRAPHIE.primes[prime].update(); }); GRAPHIE.updateTotal();
_.each(PRIMES, function(prime) { GRAPHIE.primes[prime].exponent = 0; }); _.each(getPrimeFactorization(guess), function(prime) { GRAPHIE.primes[prime].exponent += 1; }); GRAPHIE.updateTotal();
graph.cx = 0; graph.y = 0; graph.curr = NUMBER; init({ range: [[-1, FACTORIZATION.length + 1], [-2 * FACTORIZATION.length - 0.5, 1]], scale: [30, 30] }); label([graph.cx + 1, graph.y], graph.curr);

We can use a factor tree to break NUMBER into its prime factorization. Which of the prime numbers divides into NUMBER?

path([[graph.cx + 1, graph.y - 0.5], [graph.cx, graph.y - 1.5]]); path([[graph.cx + 1, graph.y - 0.5], [graph.cx + 2, graph.y - 1.5]]); graph.y -= 2; graph.cx += 1; graph.curr = graph.curr / FACTOR; label( [graph.cx - 1, graph.y], FACTOR, {color: BLUE} ); circle( [graph.cx - 1, graph.y], 0.5); graph.lastLabel = label( [graph.cx + 1, graph.y], graph.curr );

REMAINING[I] is divisible by FACTOR, leaving us with REMAINING[I] / FACTOR.

circle( [graph.cx + 1, graph.y], 0.5); graph.lastLabel.remove(); label( [graph.cx + 1, graph.y], graph.curr, {color: BLUE} );

FACTORIZATION[FACTORIZATION.length-1] is prime, so we're done factoring.

The prime factorization of NUMBER is: