Link to home
Start Free TrialLog in
Avatar of jitz
jitz

asked on

Give this a shot...

Back in my senior year of high school my shop teacher was offering extra credit for anyone that could come up with some code (Commodore 128 at the time) to answer his challenge.  Well, I graduated over 10 years ago, now play with Visual Basic 6, and his challenge still bothers me.  If anyone can help me with this I will give you all the points I have (sorry, I just joined so it's only 75).

The challenge was this:

You are building a shed and know exactly what cut lenghts of wood you need.  So now you need to go buy the wood, assuming the 2x4's (in this case it's all 2x4's) come in 8ft lenghts, how many 2x4's will you need to build the shed.

Even more extra credit was available if the cut width was added into the algorithm...

This has bothered me since 1988 and will for a while..  Any help would be great...

Thanks in advance...
Avatar of jkunal
jkunal
Flag of India image

If you fill your profile you get another 125 points
;->
hmm...I dont even know what its asking  =/
Avatar of jitz
jitz

ASKER

Sorry AzraSound, I re-read my question and realized it is a little difficult.

Basically if you needed the following lenghts:

(2) 4ft lengths
(4) 2ft lenghts
(1) 5ft lenght
(1) 3ft lenght
(1) 2ft lenght

Then you would have to purchase four 8ft 2x4's to cover your lengths, and and you would have a 6ft piece left over.

I hope this helps to explain.
I think you can try this for a solution..

Area of the shed=(Time of the day * length of shadow )-(Distance between the sun and the earth)/Time at which the first ray from the sun reached the shed.

Once we get the area we can easily solve the other problem you mentioned.

;->
Avatar of jitz

ASKER

Uhm, that sounds like a good solution as long as there is lemonade (read: Beer) involved...  hehehe
//////////////
Sorry AzraSound, I re-read my question and realized it is a little difficult.

Basically if you needed the following lenghts:

(2) 4ft lengths
(4) 2ft lenghts
(1) 5ft lenght
(1) 3ft lenght
(1) 2ft lenght

Then you would have to purchase four 8ft 2x4's to cover your lengths, and and you would have a 6ft piece left over.

I hope this helps to explain.
////////////

hey with this hint you dont need to calculate the area....

i will give you the solution but you have to increase the points to 200....

;->
//////////////
Sorry AzraSound, I re-read my question and realized it is a little difficult.

Basically if you needed the following lenghts:

(2) 4ft lengths
(4) 2ft lenghts
(1) 5ft lenght
(1) 3ft lenght
(1) 2ft lenght

Then you would have to purchase four 8ft 2x4's to cover your lengths, and and you would have a 6ft piece left over.

I hope this helps to explain.
////////////

hey with this hint you dont need to calculate the area....

i will give you the solution but you have to increase the points to 200....

;->
You need to consider every possible ordering of the cut wood and how it could be cut from the 8 foot lengths in sequence.

A question - is there actually a recognized solution to this problem, i.e is there a 'magic' combination to find which will use less pieces of wood than any other?
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
why cannot this be

(2) 4ft lengths
(4) 2ft lenghts
(1) 5ft lenght
(1) 3ft lenght
(1) 2ft lenght


like this

(2) 4ft lengths
(5) 2ft lenghts
(1) 5ft lenght
(1) 3ft lenght
deighton: Yes, there is.
I saw an example like this in one of my courses back in school. It has to do with optimization routines. I'll give it a look.
Avatar of jitz

ASKER

Wow, you actually did it!  I put the routine through a few tests and found that with higher numbers it sometimes had some extra remaining wood (2 - 4ft pieces).  But all in all I am VERY impressed!!  

Thank You!

Now, I wonder if that teacher still works at the school....

Well, it was just off the top of my head... But I'm glad you liked it.

Thanks for the points!


Cheers!®©
Try it with fractions...

AddWood 4, 2.5
Avatar of jitz

ASKER

Erick7,

I thought of that too and modified Mcriders code to allow fractions.  It's not working as well as I'd hoped, but it does work and that's fine with me...  :)
Sorry, but I didn't take fractions into consideration when I wrote that... You didn't mention it ;-)


Cheers!®©
It's common sense.
The last time I built a shed, I believe I needed some non-integer sizes of lumber.  And my saw took about a 3/32" out of each cut.

Measure twice, cut once.
Well, I dont build sheds, I build programs.. ;-)  Standard rule... If it's not in the program spec, Don't expect it in the program...


Cheers!®©
Fair enough.
At least provide the user with a warning:

MsgBox "I'm sorry, You can't use fractional cuts to build your shed"

Otherwise, the builder may not get the right number of 2x4's.

;)
Avatar of jitz

ASKER

I don't plan to use Mcriders code for anything, I just wanted to see how this sort of thing is done.  Therefore fractional lengths really weren't that big of a deal (for me), and I didn't ask for support for them.

I'm sure if you offer Mcrider some points he'd be more than happy to modify the code for you...  :)  Since he is the #2 Expert on this site..  ;)

hehe, I feel as though I'm in the presence of greatness...  :)
Avatar of jitz

ASKER

Erick37,

I must apoligize.  I see you are #7 on the experts list.  I didn't know that before now, so when I mentioned mcrider being #2 I wasn't trying to be a smart-ass or anything.  I just didn't know you were up there also.

Just wanted to say that...
jitz,
 
No genuflecting is necessary... I just like helping. ;-)


Cheers!
Avatar of jitz

ASKER

hehehehehe....

That was not worship (or genuflection), it was a simple "high five" if you will, or maybe just a "thumbs up", or how about the underrated "pat on the back"...

Now, if you were to re-do the sample you posted to handle non-integer numbers and, well, make it "bullet-proof" then, YES, it would be (minor) genuflection...  hehehe  :)

Later...