The starting block below is CODE_PARENT
units long. Use the tools to the right to convert the starting block into both of the goal blocks that are CODE_OFFSPRING_1
units long and CODE_OFFSPRING_2
units long. You can see your progress as the current blocks.
Starting Block:
Current Block 1:
Goal Block 1:
Current Block 2:
Goal Block 2:
The goal block 1 of length CODE_OFFSPRING_1
units
can be rewritten as fraction( N_OFFSPRING_1, D_OFFSPRING_1 )
.
The goal block 1 of length CODE_OFFSPRING_2
units
can be rewritten as fraction( N_OFFSPRING_2, D_OFFSPRING_2 )
.
Cutting the starting block into x
pieces is the same as dividing it by x
.
We want to cut the starting block into a piece that can be copied into both goal block 1 and goal block 2.
AThe least common denominator of D_OFFSPRING_1
and D_OFFSPRING_2
(the denominators of the goal blocks) is
LCM
. Therefore you can copy a block \dfrac{1}{LCM}
units long to make both goal blocks.
To find the number of slices to cut the starting block into we solve for s
in the following equation:
CODE_PARENT ÷ s = \dfrac{1}{LCM}
CODE_PARENT = \dfrac{1}{LCM}s
CODE_PARENT \cdot LCM = s
s = SLICES
We now have a resulting block that is \dfrac{1}{LCM}
units long. Now we simply divide our goal blocks by this value to see how many times we need to copy the resulting block.
\color{BLUE}{c1 = \dfrac{N_OFFSPRING_1}{D_OFFSPRING_1} ÷ \dfrac{1}{LCM} =
\dfrac{N_OFFSPRING_1}{D_OFFSPRING_1} \cdot LCM = N_OFFSPRING_1 * LCM / D_OFFSPRING_1}
\color{ORANGE}{c2 = \dfrac{N_OFFSPRING_2}{D_OFFSPRING_2} ÷ \dfrac{1}{LCM} =
\dfrac{N_OFFSPRING_2}{D_OFFSPRING_2} \cdot LCM = N_OFFSPRING_2 * LCM / D_OFFSPRING_2}
Therefore the solution is to cut the starting block into SLICES
pieces, copy current block 1 N_OFFSPRING_1 * LCM / D_OFFSPRING_1
times and current block 2 N_OFFSPRING_2 * LCM / D_OFFSPRING_2
times.