tags:

views:

84

answers:

1

I have a math problem that goes as follows:

I have a container which holds a total of 21000 kilos. I have 4 items A,B,C,D .

Item A weights 1 kilo. Item B weights 4 kilos. Item C weight 5 kilos. Item D weights 5 kilos also.

I am looking for an algorithm that will iterate through all possible combinations keeping the above equation. for example:

{20000 , 0, 0, 200} --> 20000*1 + 0*4 + 0*5 + 200*5 = 21000 kilos.

{19996, 1, 0, 200} --> 19996*1 + 1*4 + 0*5 + 200*5 = 21000 kilos.

Any points to the correct direction will be appreciated.

+1  A: 

This is very similar to the "Counting Change" example from SICP. See:

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2.2

Example: Counting Change

bshields
It certainly is. Here's another post on it too:http://stackoverflow.com/questions/1106929/find-all-combinations-of-coins-when-given-some-dollar-value
James Santiago
i will check em out!
Ray
you are right. it is!Thank you.
Ray