# Khan/khan-exercises

Fetching contributors…
Cannot retrieve contributors at this time
98 lines (86 sloc) 5.22 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 ) N_OFFSPRING * ( D_OFFSPRING === 1 ? D : 1 )

The starting block below is CODE_PARENT units long. Use the tools to the right to convert the starting block into the goal block that is CODE_OFFSPRING units long. You can see your progress as the current block.

Starting Block:

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

Current Block:

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

Goal Block:

init({ range: [ [ 0, 1 ], [ 0, 1 ] ],scale: [ 600 * ANSWER, 25 ] }); rectchart( [ 1, 0 ], [ BLUE, "#999" ] );
Cut into 1 piece
Copy 1 time

The starting block of length CODE_PARENT units can be rewritten as fraction( N_PARENT_EXPANDED, D ).

The goal block of length CODE_OFFSPRING units can be rewritten as fraction( N_OFFSPRING_EXPANDED, D ).

Cutting the starting block into x pieces is the same as dividing it by x.

Therefore cutting the starting block into N_PARENT_EXPANDED pieces is the same as:

\dfrac{N_PARENT_EXPANDED}{D} ÷ N_PARENT_EXPANDED = \dfrac{N_PARENT_EXPANDED}{D} \cdot \dfrac{1}{N_PARENT_EXPANDED} = \dfrac{1}{D}

Copying the resulting block y times is the same as multiplying it by y.

Therefore copying the resulting block N_OFFSPRING_EXPANDED times is the same as:

\dfrac{1}{D} \cdot N_OFFSPRING_EXPANDED = \dfrac{N_OFFSPRING_EXPANDED}{D}

Notice that we end up with a block the same size as the goal block.

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

Something went wrong with that request. Please try again.