Page 1 of 1

Array Calculation Problems

Posted: Mon Jan 02, 2006 7:09 am
by AGISB
I got a problem and I only got a time consuming solution.

I got a array with recipes including total calories. Now I want to create a daily menu with lets say 1500 calories max.

However I want to get as close to the 1500 as possible.

Now there is an array for breakfast, lunch and dinner.


My solution for now is start with breakfast and then add the highest calorie lunch and then starting to add dinner recipes untill it fits. If I get over the 1500 with each I take the next lunch recipe and go again with the dinner recipes and so on. This seems timeconsuming to me. Anyone got another solution idea?

I don't want to recompile the daily menus and do it on the fly. However this will be done by a cgi application once a day.

Re: Array Calculation Problems

Posted: Mon Jan 02, 2006 8:22 am
by BDKR
AGISB wrote: I don't want to recompile the daily menus and do it on the fly. However this will be done by a cgi application once a day.
Without getting into the other algorythmic issues I'll offer something relating to the above quote. If you don't want to do all this calculating on a daily basis, don't. Why not run through each possilbe combination and only store those that are acceptable in a look up table of sorts. If you later add a new dish at say breakfast or dinner, run a script or program to recompute the entire thing.

Posted: Mon Jan 02, 2006 8:27 am
by AGISB
While going to the grocery store I had the same idea. It will get kind of big but I will just test it

Posted: Mon Jan 02, 2006 8:37 am
by BDKR
AGISB wrote:It will get kind of big but I will just test it
Sure it could get kind of big, but it's better then creating it daily. Just be careful how you store it.