title: How to "blend" two values without overflow?
body: <p>Consider the following function:</p>
  
  <pre><code>// Return a blended value of x and y:
  //   blend(100, 200, 1, 1) -&gt; 150
  //   blend(100, 200, 2, 1) -&gt; 133
  uint8_t blend(uint8_t x, uint8_t y, uint8_t parts_x, uint8_t parts_y) {
    uint32_t big_parts_x = parts_x;
    uint32_t big_parts_y = parts_y;
    return (uint8_t) ((big_parts_x * x + big_parts_y * y) /
                      (big_parts_x + big_parts_y));
  }
  
  </code></pre>
  
  <p>Is there a way to get <em>close</em> to appropriate return values without requiring any allocations greater than <code>uint8_t</code>? You could break it up (less rounding) into an addition of two <code>uint16_t</code> easily by performing two divisions. Can you do it with only <code>uint8_t</code>?</p>