randRange( 2, 6 ) shuffle( getPrimeFactorization( 60 ).concat( getPrimeFactorization( DISTANCE ) ) ) function( factors ) { var product = 1; for ( var i = 0; i < factors.length; i++ ) { product *= factors[ i ]; } return product; } randRange( 3, FACTORS.length - 2 ) MULTIPLY( FACTORS.slice( 0, SPLIT ) ) MULTIPLY( FACTORS.slice( SPLIT ) ) (function() { if ( RATE_UP % 3 === 0 ) { return 2; } else { return 3; } })() K * RATE_UP 60 * DISTANCE / RATE_DOWN 60 * 2 * DISTANCE / ( TIME_UP + TIME_DOWN )

Starting at home, person( 1 ) traveled uphill to the store( 1 ) store for TIME_UP minutes at just RATE_UP mph. He( 1 ) then traveled back home along the same path downhill at a speed of K * RATE_UP mph.

What is his( 1 ) average speed for the entire trip from home to the store( 1 ) store and back?

RATE_AVG mph

The average speed is not just the average of RATE_UP mph and RATE_DOWN mph.

He( 1 ) traveled for a longer time uphill (since he( 1 ) was going slower), so we can estimate that the average speed is closer to RATE_UP mph than RATE_DOWN mph.

To calculate the average speed, we will make use of the following:

\text{average speed} = \dfrac{\color{KhanUtil.BLUE}{\text{total distance}}}{\color{KhanUtil.ORANGE}{\text{total time}}}

\text{distance uphill} = \text{distance downhill}

What was the total distance traveled?

\color{KhanUtil.BLUE}{\begin{align*}\text{total distance} &= \text{distance uphill} + \text{distance downhill}\\ &= 2 \times \text{distance uphill}\end{align*}}

\begin{align*}\text{distance uphill} &= \text{speed uphill} \times \text{time uphill} \\\ &= RATE_UP\text{ mph} \times TIME_UP\text{ minutes}\times\dfrac{1 \text{ hour}}{60 \text{ minutes}}\\ &= DISTANCE\text{ miles}\end{align*}

Substituting to find the total distance:

\color{KhanUtil.BLUE}{\text{total distance} = 2 * DISTANCE\text{ miles}}

What was the total time spent traveling?

\color{KhanUtil.ORANGE}{\text{total time} = \text{time uphill} + \text{time downhill}}

\begin{align*}\text{time downhill} &= \dfrac{\text{distance downhill}}{\text{speed downhill}}\\ &= \dfrac{DISTANCE\text{ miles}}{RATE_DOWN\text{ mph}}\times\dfrac{60 \text{ minutes}}{1 \text{ hour}}\\ &= TIME_DOWN\text{ minutes}\end{align*}

\color{KhanUtil.ORANGE}{\begin{align*}\text{total time} &= TIME_UP\text{ minutes} + TIME_DOWN\text{ minutes}\\ &= TIME_UP + TIME_DOWN\text{ minutes}\end{align*}}

Now that we know both the total distance and total time, we can find the average speed.

\begin{align*}\text{average speed} &= \dfrac{\color{KhanUtil.BLUE}{\text{total distance}}}{\color{KhanUtil.ORANGE}{\text{total time}}}\\ &= \dfrac{\color{KhanUtil.BLUE}{2 * DISTANCE\text{ miles}}}{\color{KhanUtil.ORANGE}{TIME_UP + TIME_DOWN\text{ minutes}}}\times\dfrac{60 \text{ minutes}}{1 \text{ hour}}\\ &= RATE_AVG\text{ mph}\end{align*}

The average speed is RATE_AVG mph, and which is closer to RATE_UP mph than RATE_DOWN mph as we expected.

randRange( 5, 10 ) PEOPLE_INIT randRange( 20, 59 ) randRange( PEOPLE_INIT + 3, 20 ) PEOPLE_FINAL TIME_INIT

It takes TIME_INIT minutes for PEOPLE_INIT people to paint WALL_INIT walls.

How many minutes does it take PEOPLE_FINAL people to paint WALL_FINAL walls?

TIME_FINAL minutes

Imagine that each person is assigned one wall, and all PEOPLE_INIT people begin painting at the same time.

Since everyone will finish painting their assigned wall after TIME_INIT minutes, it takes one person TIME_INIT minutes to paint one wall.

If we have PEOPLE_FINAL people and WALL_FINAL walls, we can again assign one wall to each person.

Everyone will take TIME_FINAL minutes to paint their assigned wall.

In other words, it takes TIME_FINAL minutes for PEOPLE_FINAL people to paint WALL_FINAL walls.

randRangeUnique( 3, 7, 2 ) randRange( 30, 50 ) randRange( PEOPLE_INIT + 1, 10 ) randRange( WALL_INIT + 1, 10 ) round( WALL_FINAL * TIME_INIT * PEOPLE_INIT / ( WALL_INIT * PEOPLE_FINAL ) ) getGCD( WALL_FINAL * TIME_INIT * PEOPLE_INIT, WALL_INIT * PEOPLE_FINAL ) !== (WALL_INIT * PEOPLE_FINAL)

PEOPLE_INIT people can paint WALL_INIT walls in TIME_INIT minutes.

How many minutes will it take for PEOPLE_FINAL people to paint WALL_FINAL walls? Round to the nearest minute.

TIME_FINAL minutes

the number of minutes, rounded to the nearest minute

We know the following about the number of walls w painted by p people in t minutes at a constant rate r.

w = r \cdot t \cdot p

\begin{align*}w &= WALL_INIT\text{ walls}\\ p &= PEOPLE_INIT\text{ people}\\ t &= TIME_INIT\text{ minutes}\end{align*}

Substituting known values and solving for r:

r = \dfrac{w}{t \cdot p}= \dfrac{WALL_INIT}{TIME_INIT \cdot PEOPLE_INIT} = fractionReduce( WALL_INIT, TIME_INIT * PEOPLE_INIT )\text{ walls painted per minute per person}

We can now calculate the amount of time to paint WALL_FINAL walls with PEOPLE_FINAL people.

t = \dfrac{w}{r \cdot p} = \dfrac{WALL_FINAL}{fractionReduce( WALL_INIT, TIME_INIT * PEOPLE_INIT ) \cdot PEOPLE_FINAL} = \dfrac{WALL_FINAL}{fractionReduce( WALL_INIT * PEOPLE_FINAL, TIME_INIT * PEOPLE_INIT )} = fractionReduce( WALL_FINAL * TIME_INIT * PEOPLE_INIT, WALL_INIT * PEOPLE_FINAL )\text{ minutes}= mixedFractionFromImproper( WALL_FINAL * TIME_INIT * PEOPLE_INIT, WALL_INIT * PEOPLE_FINAL, true, true )\text{ minutes}

Round to the nearest minute:

t = TIME_FINAL\text{ minutes}