Question Can't figure out how to code this :(

sam1ck

New member
Joined
Aug 26, 2012
Messages
3
Programming Experience
Beginner
Hi all, I'm currently trying to complete a school assignment, but I'm stumped on what the easiest way would be to approach this.


Problem:


Bob is an interior decorator.

He works with rolls of curtains that measure 5m wide & 3m long (each.)

Bob needs a calculator that will tell him how much excess curtain he will be left with on his last roll of curtain - if he was to cover, say 50m by 20m.

-

Examining the facts:

We both know that Bob will use 10 rolls of curtains in order to achieve this.

And that he will be left with 10m's of excess curtain on the length.

-

But how does one put this into code and be able to devise a formula that will calculate the left over curtain excess?

(Feel free to change the content of my described problem, as long as it gets the result of calculating the excess I'll be a-okay.)

All help is appreciated

Thanks in advance!
 
I'm not sure how you arrive to 10 rolls, when 50x20 = 1000m2 and 5x3x10 = 150m2. In any case, once you figure out that you need 10 rolls just to do the length and 7 times to cover the width, you know that this gives you 1m x 50m, so 50m2 is lost, unless you reuse the cutoffs in which case 50m2 \ 15m2 (one roll) = -3 rolls, you need 67, and have 5m2 extra. Or, if you arrange them the other way around, you need 4 rolls to cover the width and 17 rolls to cover the length, so 68 rolls and are left with 6m2 extra. If you were to criss cross them like tiles, you would likely get a different figure.

These algorithms can get quite complex, since you need to account for every possible way to arrange each roll. You need some constraints (for example, the length must always be aligned to the X axis),
 
Last edited:
Computers are not magic. They just do what people do except a lot faster. How would you calculate the solution with a pen and paper? You do it the same way with code. Just like any problem, you should be coming up with an algorithm first. You should be able to apply the algorithm manually to the problem and come up with the correct answer no matter the input parameters. Once you have the algorithm, you have the solution. It's then just a matter of implementing that solution in code. If you can't solve the problem with pen and paper then you can't do it with code either, because you don't know what the code is actually supposed to do.
 
I'm not sure how you arrive to 10 rolls, when 50x20 = 1000m2 and 5x3x10 = 150m2.

Sorry if I've confused you.

The roll of curtain is 5 metres wide by 3 metres long.

So if I were to cover a window that is measuring 50 metres wide by 20 metres long, I will need 10 rolls of curtains with an excess of 10 metres of curtain left over.

If you can't solve the problem with pen and paper then you can't do it with code either, because you don't know what the code is actually supposed to do.

Thanks for your very informative reply, it helped me confirm some of my unanswered theories.

I understand that I might be making this unnecessarily difficult for myself (involuntarily), that's why I suggested that anyone can feel free to manipulate the content into a more suitable logic.

I've attach a screenshot of the assignment sheet I'm working off & a paste bin of my current code if anyone wants to review what I've done so far.

Screenshot: http://iforce.co.nz/i/1hoosw4k.5pv.jpg (pic is no longer sideways)
Code: [VB.NET] working progress - Pastebin.com
 
Sorry if I've confused you.

The roll of curtain is 5 metres wide by 3 metres long.

So if I were to cover a window that is measuring 50 metres wide by 20 metres long, I will need 10 rolls of curtains with an excess of 10 metres of curtain left over.

I once again need to ask in which mathematical model 150m2 (3mx5mx10) is enough to cover a surface of 1000m2 (20mx50m). This is simple high school geometry.
 
I once again need to ask in which mathematical model 150m2 (3mx5mx10) is enough to cover a surface of 1000m2 (20mx50m). This is simple high school geometry.

You're absolutely right! I had a huge visualizing & math lapse my apologies - now that you've helped me figured that out everything's falling into place.

Much appreciated, thanks :)
 
Back
Top