title: Calculating truck cargo capacity in a game
body: <p>This is more of a math/algorithm question than a programming question, but I hope you guys can help anyway.</p>
  <p>Scenario #1:</p>
  <blockquote>
  <p>Player 1 has 40 <code>crates</code> in his inventory.</p>
  <p>Player 1 has 2 <code>trucks</code>,</p>
  <p>1x <code>small</code>  (capacity: 8 crates)</p>
  <p>1x <code>medium</code> (capacity: 16 crates)</p>
  </blockquote>
  <hr />
  <blockquote>
  <p>Given <code>capacity</code>:</p>
  <p>A <code>small</code> truck can hold 8 crates</p>
  <p>A <code>medium</code> truck can hold 16 crates</p>
  <p>A <code>large</code> truck can hold 30 crates</p>
  </blockquote>
  <p>How many trucks does player 1 need to be able to take all 40 crates?</p>
  <p>Scenario #2, what happens if there is cargo already in trucks?</p>
  <blockquote>
  <p>Player 1 has 40 crates and 2 trucks as above scenario.</p>
  <p>If <code>small</code> already has 2 crates in its load, giving him 8-2 = 6 space</p>
  <p>If <code>medium</code> already has 4 crates in its load, giving him 16-4 = 8 space</p>
  <p>How many trucks does player 1 need to take all 40 crates?  What would the algorithm be?</p>
  </blockquote>
  <p>Scenario #3: No trucks</p>
  <blockquote>
  <p>Player 1 has 0 trucks at all.  How many trucks does he need to take all 40 crates?  Again, what is the algoritm you would use?</p>
  </blockquote>
  <p>Scenario #4: Too many trucks</p>
  <blockquote>
  <p>Player 1 has 10 trucks, all at <code>large</code> capacity.  How many trucks does it take to ship all 40 crates?</p>
  </blockquote>
  <p>I'm thinking.</p>
  <p>Scenario 1,</p>
  <pre><code>2 trucks, 1 small = 8 and 1 medium = 16
  8+16 = 24 crates
  40 - 24 = 16 trucks?? // This looks wrong.
  </code></pre>
  <p>Costs of trucks are done earlier on (you buy them first).</p>
  <p>I think my algorithm is wrong.  Do I need to divide it by a base number?  Do I divide it by trucks?</p>
  <p>Any help on this would be very helpful.</p>