# Rectangular Prisms

Eight corner bricks are taken out from a 5x5x5 block, which is something like below:

How many rectangular prisms of all sizes can be counted in this block?

Source: Oyun 2018 Final Exam Question

• Does a cube count as a rectangular prism?? – Kevin L Aug 17 '18 at 12:48
• we dont know if any group of prism creates a cube and since dimensions are not given, yes you will count cubes as prisms. – Oray Aug 17 '18 at 12:50
• ok gonna start counting :) – Kevin L Aug 17 '18 at 12:51
• and according to wyzant.com/resources/answers/4393/… cube is also rectangular prism. – Oray Aug 17 '18 at 12:52
• Since Gareth McCaugham has corrected his slight mistake you should credit him with the accepted answer, for anteriority and for the redaction effort that I just copied and pasted. – Evargalo Aug 17 '18 at 20:57

Suppose we leave the corners there. Then

a rectangular prism (= cuboid) is defined by three pairs of planes, so there are $\binom{6}{2}^3=15^3=3375$ of these.

How many of these are excluded by having no corners?

A cuboid $[a,b]\times[c,d]\times[e,f]$ uses a corner iff ($a=0$ OR $b=5$) AND ($c=0$ OR $d=5$) AND ($e=0$ OR $f=5$). The number of ways to choose $(a,b)$ so that this happens is 11, so there are $11^3=1331$ of these.

Oops, turns out I meant 9 not 11. 01 02 03 04 05 15 25 35 45. So 729 rather than 1331, leading to a correspondingly larger final answer.

So the number of "good" cuboids is

3375 minus 1331 = 2044. [EDITED to add:] Nope, 3375-729 = 2646.

• you're counting a=b=0 etc. – JonMark Perry Aug 17 '18 at 13:48
• Yes, I am. There are six relevant planes for each axis, from x=0 to x=5 etc. Any way of picking two different ones on each axis yields a cuboid. – Gareth McCaughan Aug 17 '18 at 15:40
• Oh, sorry, you mean I'm counting (0,0) as well as (0,5) etc.? No, I wasn't. I did miscount, but it was a simple off-by-one error rather than anything that interesting. – Gareth McCaughan Aug 17 '18 at 15:49
• it looks like you counted [0,0]x[1,3]x[2,4] for example (in the second part) – JonMark Perry Aug 17 '18 at 15:52
• I don't think so. I think I just thought "01 02 ... 05 / 05 15 ... 45, one overlap, that'll be 11" when in fact it should have been 9. I'm not sure my thought process was even as conscious as that. – Gareth McCaughan Aug 17 '18 at 16:45

I think Gareth McCaughan has the right reasoning but a small calculation error. I'll copy his explanations here :

Suppose we leave the corners there. Then

Let's give coordinates to the cubes from 1 to 5 in length, width and height. A rectangular prism (= cuboïd) is defined by its smallest and biggest index (possibly equal) on each axis, so there are $(\binom{5}{2}+5)^3=15^3=3375$ of these.

How many of these are excluded by having no corners?

A cuboïd $[a,b]\times[c,d]\times[e,f]$ uses a corner iff ($a=1$ OR $b=5$) AND ($c=1$ OR $d=5$) AND ($e=1$ OR $f=5$). The number of ways to choose $(a,b)$ so that this happens is $9$, so there are $9^3=729$ of these.

Alternatively, by inclusion/exclusion:

There are $5 \times 5 \times 5=125$ cuboïds using the 'vanished' $(1,1,1)$ corner cube, and $8$ ways to pick a corner.
There are $5 \times 5=25$ cuboïds using the 'vanished' $(1,1,1)$ and $(1,1,5)$ cubes, and $12$ ways to pick an edge.
There are $5$ cuboïds using the four 'vanished' $(1,1,1)$, $(1,5,1)$, $(1,5,5)$ and $(1,1,5)$ cubes on any given face, and $6$ ways to pick a face.
There is $1$ cuboïd using all eight 'vanished' corner cubes.
The number of 'wrong' cuboïds is then: $(125 \times 8)-(25 \times 12)+ (5 \times 6) -1=729$

So the number of "good" cuboïds is

$3375 - 729 = \mathbf{2646}$.

• Evargalo, I think you had it initially correct in your alternative explanation; your math no longer tallies in the final equation of your third paragraph. – El-Guest Aug 17 '18 at 13:43
• @El-Guest. Thanks, I've edited and I hope it is correct now. – Evargalo Aug 17 '18 at 13:44
• Looks much better. I can clean up some of the math formatting for you as well. – El-Guest Aug 17 '18 at 13:46
• Evargalo, what do you think of the edited version? I just wanted to clean up some of the x vs. \times differences, etc. Great catch, though. – El-Guest Aug 17 '18 at 13:49
• This is slightly incorrect because it has "1 or 5" everywhere, where it should be "0 or 5". I confess myself slightly miffed that someone else is getting the coveted green checkmark for copying-and-pasting my answer, fixing a trivial error, and making another trivial error in turn, but never mind. I suppose there's the inclusion-exclusion bit. (I decided not to do it that way because the argument I actually gave was much easier to follow.) – Gareth McCaughan Aug 17 '18 at 15:47

A computer version in JavaScript:

<!doctype html>
<html>
<title>Cuboids</title>
<body>
<span id='out'></span><br>
<button onclick='go();'>go</button>
</body>

<script>

function go() {
var d=0;
for (let a=0;a<15;a++)
for (let b=0;b<15;b++)
for (let c=0;c<15;c++)
if ((a==0 || a==1 || a==2 || a==3 || a==4 || a==8 || a==11 || a==13 || a==14) &&
(b==0 || b==1 || b==2 || b==3 || b==4 || b==8 || b==11 || b==13 || b==14) &&
(c==0 || c==1 || c==2 || c==3 || c==4 || c==8 || c==11 || c==13 || c==14)) d++;
out.textContent=d;

d=0;
for (let a=0;a<5;a++)
for (let b=0;b<5;b++)
for (let c=0;c<5;c++)
d+=countCuboids(a,b,c);
out.textContent+='  ::  '+d;
}

function countCuboids(a,b,c) {
if (a%4==0 && b%4==0 && c%4==0) return 0;
if (a%4>0 && b%4==0 && c%4==0) return (4-a)*(5-b)*(5-c);
if (a%4==0 && b%4>0 && c%4==0) return (5-a)*(4-b)*(5-c);
if (a%4==0 && b%4==0 && c%4>0) return (5-a)*(5-b)*(4-c);
if (a%4>0 && b%4>0 && c%4==0) return (5-a)*(5-b)*(5-c)-(5-c);
if (a%4>0 && b%4==0 && c%4>0) return (5-a)*(5-b)*(5-c)-(5-b);
if (a%4==0 && b%4>0 && c%4>0) return (5-a)*(5-b)*(5-c)-(5-a);
if (a%4>0 && b%4>0 && c%4>0) return (5-a)*(5-b)*(5-c)-1;
}

</script>

</html>


The first version maps $0..14$ to $1,12,123,1234,12345,2,23,234,2345,3,34,345,4,45,5$ and counts anything that has a $1$ or a $5$ in all three loop variables.

Result: 729 (=$15^3-2646$)

The second uses an explicit function to calculate the number of right, up, back cuboids from a starting cube, and sums them.

Result: 2646