# Khan/khan-exercises

Fetching contributors…
Cannot retrieve contributors at this time
150 lines (133 sloc) 8.26 KB
 Fractions cut and copy 1
randRangeWeighted(3, 12, 1, 1 / 6) D_PARENT === 1 ? randRange(3, 12) : (rand(5) > 0 ? D_PARENT : 1)
D_PARENT === 1 ? randRange(1, 4) : randRangeExclude(2, 2 * D_PARENT - 1, [D_PARENT]) D_OFFSPRING === 1 ? randRange(1, 4) : randRangeExclude(2, 2 * D_OFFSPRING - 1, [D_OFFSPRING])
D_PARENT === 1 ? N_PARENT : mixedOrImproper(N_PARENT, D_PARENT) D_OFFSPRING === 1 ? N_OFFSPRING : mixedOrImproper(N_OFFSPRING, D_OFFSPRING) N_PARENT / D_PARENT N_OFFSPRING / D_OFFSPRING OFFSPRING / PARENT D_PARENT === 1 ? D_OFFSPRING : D_PARENT N_PARENT * (D_PARENT === 1 ? D : 1) _(floor(N_PARENT / D_PARENT)).times(function() { return fraction(D, D);}).join("+") N_OFFSPRING * (D_OFFSPRING === 1 ? D : 1) _(floor(N_OFFSPRING / D_OFFSPRING)).times(function() { return fraction(D, D);}).join("+")

The starting block below is CODE_PARENT unit long. The starting block below is CODE_PARENT units long. Use the tools below to convert the starting block into the goal block that is CODE_OFFSPRING unit long. Use the tools below to convert the starting block into the goal block that is CODE_OFFSPRING units long. The current block shows your progress.

Starting Block:

initSliceClone(["current_block"]); init({range: [[0, 1], [0, 1]], scale: [500, 25 ]}); rectchart([1, 0], [RED, "#999"]);

Current Block:

init({ range: [[0, 1], [0, 1] ], scale: [500, 25]}); rectchart([1, 0], [RED, "#999"]);

Goal Block:

init({range: [[0, 1], [0, 1]], scale: [500 * ANSWER, 25]}); rectchart([1, 0], [BLUE, "#999"]);
Cut into: 1 piece
Copy: 1 time
[pieces, times['current_block']]
return roundTo(3, guess[1] / guess[0]) === roundTo(3, ANSWER);
pieces = guess[0]; times['current_block'] = guess[1]; updateGraphAndAnswer();
$('#pieces').text(plural(guess[0], 'piece'));$('#current_block_times').text(plural(guess[1], 'time'));

The starting block has a length of CODE_PARENT, which can be rewritten as:

\qquadPARENT_EXPANSION + fraction(N_PARENT - D, D_PARENT) = fraction(N_PARENT_EXPANDED, D)

The goal block has a length of CODE_OFFSPRING, which can be rewritten as:

\qquad OFFSPRING_EXPANSION + fraction(N_OFFSPRING - D, D_OFFSPRING) = fraction(N_OFFSPRING_EXPANDED, D)

fraction(N_PARENT_EXPANDED, D) is the same thing as N_PARENT_EXPANDED \times fraction(1, D).

Therefore, if we cut the starting block into N_PARENT_EXPANDED equal pieces, each piece will have a length of fraction(1, D) units.

If we copy a piece N_OFFSPRING_EXPANDED times, we will get a length of N_OFFSPRING_EXPANDED \times fraction(1, D) = fraction(N_OFFSPRING_EXPANDED, D) units.

Therefore the solution is to cut the starting block into N_PARENT_EXPANDED pieces and copy the resulting block N_OFFSPRING_EXPANDED times.