Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Like a pick-3 lottery, the 3 dimensions could represent any position, such as laying thebrick flat, on its end tall, or on its side. So, that said, we have 6 combinations based on ex: 123, 132, 213, 231, 312, 321 where each number is in a respective position. If you have some oddball dimensions, such as 25x33x40 and a brick dimension of 11x10x5 (yeah, right) it won't necessarily make sense that the 11 correspond to 25, 10 to 33, 5 to 40, but if you DID compute based on that, you would get 2 bricks per 25, 3 per the 33 and 8 per the 40 or 2x3x8 = 48 bricks.</p> <p>Now, if tried where the 11 is in the second position, the 10 in the last position and 5 in the first, you get 5:25, 11:33 and 10:40 or 5 bricks by 3 bricks by 4 bricks 5x3x4 = 60 bricks since we can't cut bricks into fractions and you were handling this by using FLOOR. So, I would try all 6 combinations and just take the highest.</p> <p>Notice on how I'm testing. I'm ALWAYS leaving the dimensions of the box to length,width,height respectively. Then, in the loop, All I'm doing is changing the TEST variable "l"ength, "w"idth, and "h"eight to each of the respective 6 combinations like a pick-3 lottery. By testing the integer of each will give its own value based on that way being laid in the box for stacking... whichever way has the most wins.</p> <p>So, for pass 0/1, the LENGTH var stays the same, and h/w swap. in pass 2/3, the WIDTH is in the first position and swap l/h, finally in pass 4/5, the HEIGHT is in the first position and swap l/w. So all 6 combinations accounted for.</p> <p>Example calls</p> <pre><code>totalBricks = BricksPerDimension(20, 70, 30, 1, 2, 5); MessageBox.Show(totalBricks.ToString()); totalBricks = BricksPerDimension(25, 33, 40, 11, 10, 5); MessageBox.Show(totalBricks.ToString()); </code></pre> <p>And the updated function</p> <pre><code>private static int BricksPerDimension(int dimWidth, int dimLength, int dimHeight, int brickSideWidth, int brickSideLength, int brickSideHeight) { int maxBricks = 0; int curBricks = 0; int l, w, h; l = w = h = 0; for (int i = 0; i &lt; 6; i++) { switch (i) { case 0: l = brickSideLength; h = brickSideHeight; w = brickSideWidth; break; case 1: l = brickSideLength; w = brickSideHeight; h = brickSideWidth; break; case 2: w = brickSideLength; l = brickSideHeight; h = brickSideWidth; break; case 3: w = brickSideLength; h = brickSideHeight; l = brickSideWidth; break; case 4: h = brickSideLength; l = brickSideHeight; w = brickSideWidth; break; case 5: h = brickSideLength; w = brickSideHeight; l = brickSideWidth; break; } curBricks = ((int)dimLength / l) * ((int)dimWidth / w) * ((int)dimHeight / h); if (curBricks &gt; maxBricks) maxBricks = curBricks; } return maxBricks; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload