Math - Inequalities - Challenge

In this lecture we learnt how to manipulate inequalities.

For your challenge, our designer wants to know how many times the player can refuel and still afford an upgrade at the end of the level.

We know that:

  • Pickups are worth 5 coins each
  • There are 30 pickups in a level
  • Refueling costs 10 coins
  • Upgrades cost 100 coins

For a hint, we can express our problem as:
(30 x 5) - (10n) >= 100

So we need to rearrange and solve for n.

Post your answers below and remember to use the spoiler tags.

Summary

float pickup = 30 * 5;
float refuel = 10;
float upgrade = 100;
float n;

n <= (upgrade - pickup) / -refuel;

n <= 5

1 Like

(30 * 5) - 10n >= 100

150 - 10n - 100 >= 0
150 - 100 >= 10n
50/10 >= n
n <= 5

1 Like

With the equation (30*5) - (10n) >= 100

30*5 = 150 so 150-10n >= 100

-150 + 150 - 10n = 100-150 so -10n >= -50

-10n/-10 >= -50/-10 so n <= -50/-10

or

n <= 5

1 Like

So I got no more than 5 refuels and it was pretty easy solving it, however I think the hardest part of this, you actually did for us, namely expressing the whole thing as an inequality. As soon as you explained the problem, I sort of calculated it intuitively but I wasn’t thinking iun terms of inequalities.

I think it would be good to learn how to express these problems formally in math language for when more complex problems that are not so cognitively intuitive come along.

My take away from this lesson is that we expressed the >= sign as “has got to be less or equal to”, in other words we formulate maths statements to require something rather than to discover (in this case at least)

1 Like

@olidadda, one of the hardest parts of maths is converting your word problem into math terms.
Hopefully me talking through the problem helps you get a better sense of the thought process that goes into getting from one to the other.

Rather that just drop you in at the deep end I do like to give you a helping hand where I can in these early stages of the course, but that help does start to turn into smaller and smaller hints as we move through the course.

And it’s great to hear you got an intuitive feel for the answer before actually solving it.
That’s a good skill to develop and will help you a great deal in the long run.

In your last paragraph though, >= is “greater or equal to” (I think you meant <=).
You’re general thought process seems sound though. Inequalities deal with ranges of possible answers, so they come up a lot in programming - especially for things like if-statements.

1 Like