# Homework Help: Empty Boxes Invariant/Algorithmic Problem

1. Jan 25, 2014

### SpunkyDonutz

I've been trying to figure this out for a couple of hours and I just don't know how to work it out, I have attempted to create a valid statement for the algorithm, but I just don't know what I'm doing.

I would be greatly appreciative for any help I could get on this.

Thanks!

1. The problem statement, all variables and given/known data

Twenty-ﬁve large empty boxes are placed on a table. An unknown
number of the boxes is selected and, into each, seven medium boxes are placed. An
unknown number of the medium boxes is selected and, into each, seven small boxes
are placed.

At the end of this process there are 291 boxes in total. How many empty boxes
are there? You should use the following steps in order to solve the problem.

1. Introduce the variables e and t for the number of empty and the number of
total boxes, respectively.
2. Identify the information that is given about the initial and ﬁnal values of e and
t.
3. Model the process of putting seven boxes inside a box as an assignment to e
and t.
4. Calculate an invariant of the assignment.
5. Combine the previous steps to deduce the ﬁnal value of e .

2. Relevant equations
3. The attempt at a solution
Initial:
e = 25
t = 291
Final:
e = ?
t = 291

(e-t)[e, t := e+7, t-1]
=
(e+7) – (t-1)
=
e-t-5

Last edited: Jan 25, 2014
2. Jan 25, 2014

### tiny-tim

Hi SpunkyDonutz! Welcome to PF!
The question is asking for the total number of empty large boxes, plus empty medium boxes, plus all the small boxes (since they're all empty anyway).

Try the first stage (before any of the small boxes have arrived) … if n large boxes are filled, how many empty boxes are there? … then try the final stage.

3. Jan 25, 2014

### SpunkyDonutz

So essentially the assignment should look something like this?
e := (25 - L) + (8 - M) + 8

and the invariant is going to be t - e?

4. Jan 25, 2014

### tiny-tim

why?

(and shouldn't there be some 7s in there?)

5. Jan 25, 2014

### SpunkyDonutz

Derp, I meant 7 instead of 8 :\$

Well if there's 25 large boxes in total, and L amount of filled boxes, you would substitute L from 25.
And you would do the same with the medium boxes.
Then add them up and add the amount of small boxes on (since they're always empty).

6. Jan 25, 2014

### tiny-tim

you mean (25 - L) + (7 - M) + 7 ?

but what about that huge number of medium boxes that end up empty?

7. Jan 25, 2014

### SpunkyDonutz

I'm confused now

8. Jan 25, 2014

### tiny-tim

the medium boxes that don't have small boxes inside are all empty

9. Jan 25, 2014

### SpunkyDonutz

I know that much, I'm just confused about how to work that out

10. Jan 25, 2014

### tiny-tim

sorry, but we're not going to give you the answer

you'll have to work it out​

11. Jan 25, 2014

### SpunkyDonutz

I know, I don't expect the answer, just hopefully something that'll help flick the switch.
Is this more along the right lines?
e := (25 - L) + (7 - m) + (7 - s)

12. Jan 25, 2014

### tiny-tim

??

explain​

13. Jan 25, 2014

### SpunkyDonutz

25 - L = the amount of empty large boxes
7 - M = the amount of empty medium boxes
7 - S = the amount of empty small boxes

14. Jan 25, 2014

### tiny-tim

why??

15. Jan 25, 2014

### SpunkyDonutz

Ahh, I see what you mean now...

7-7M

7M - because there are 7 boxes placed and M are full?

16. Jan 25, 2014

### tiny-tim

??

is L the number of large boxes that are filled?

if so, what is total number of medium boxes?​

17. Jan 25, 2014

### SpunkyDonutz

Yeah, L, M and S are the total amount filled.
8*L?

18. Jan 25, 2014

### tiny-tim

you mean 7*L

and the total number of small boxes?

19. Jan 25, 2014

### SpunkyDonutz

That would be 7*M

20. Jan 25, 2014

### tiny-tim

yes

ok so what is the total number of empty boxes?

(and what is the total number of all boxes, in terms of L and M?)

btw, i didn't notice …
… no, none of the small boxes are filled

21. Jan 25, 2014

### SpunkyDonutz

(25 - L) - (7 - 7L) - (7 - 7M)?

25 + 7M would be for the total of L and M

22. Jan 25, 2014

### tiny-tim

sorry, you've really confused me, i've lost track of what you say L and M are

i'm going to bed, we'll have another go tomorrow :zzz:​

23. Jan 25, 2014

### SpunkyDonutz

Alright, thanks a lot for the help, I really appreciate it!
Night mate!

L is the number of full large boxes.
M is the number of full medium boxes.

I think I should have had:
(25 - L) - (7L - M) - 7M

(25 -L) Total number of empty large boxes
(7L - M) Total number of empty medium boxes
7M Total number of small boxes

24. Jan 26, 2014

### tiny-tim

(just got up :zzz:)
yes!!

(btw, do you see how straightforward it is if you choose a sensible notation, and carefully rewrite everything step by step in that notation?)
minus????

ok, now:
i] simplify that (after you've corrected it)
ii] what is the total number of all boxes (in terms of L and M), that has to be 291 ?​

25. Jan 26, 2014

### SpunkyDonutz

(25 - L) + (7L - M) + 7M

25 + 6L + 6M?

25 Large Boxes in total
175 Medium Boxes in total

18 of the 25 Large Boxes would have to be used
Meaning 126 medium boxes are used, and 21 of those boxes would be used
Giving 147 small boxes.

18+126+147 = 291

Last edited: Jan 26, 2014