Jump to content

ProductionOptimization problem


Recommended Posts

  • 1 month later...

Add up all the values in the cost array, except the last one, and subtract it from the total cost. Divide what's left by the last value in the array, and round it down to the nearest whole number. Do the same thing for the times array. When you have the two results, find the smaller one, and if it's less than 0, make it zero and return it from the function ;)

 

You're 3rd example seems to be wrong, but the others are all right...

Link to comment
Share on other sites

The examples are part of the problem statement and all of them are right. You method doesn't work, take #3 for example:

 

{1, 1}

{3, 12}

100

27

Returns: 6

 

Lets say the cost is in $...

each unit costs $1, the first takes 3 sec and the second takes 12 sec. You have a total of $100 to spend and 27 secs. Using you method, you'll make 1 of the first unit, spending $1 and 3 seconds leaving you with $99 and 24 seconds. If you just keep making the 2nd unit from this, you'll only end up with 2 of them. If you make more of the first unit, then they can each simultaneously create the second type of units allowing more to be built in the allotted time.

Link to comment
Share on other sites

Ah, I didn't realise that more than one could be being built at the same time.

 

It sounds like you could use a recursive function. All you have to do is call the function for every possible combination of units that can be built. Once that function has built those, it then calls itself for every new combination, and so on until all the combinations are exhausted. Then, find the one that created the most of the highest level unit. Only count a combination if you have enough time and money for it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...