Simple Combo/Permute calculation

45 replies · 6K views · last reply
DaveC426913
Gold Member
2025 Award
Messages
24,779
Reaction score
9,206
TL;DR
How many possible shapes can there be, given these parameters?
I'm playing a Steam game called Shapez wherein the goal is to produce and deliver given shapes to the Hub by conveyor belt.

Screenshot of the Shapez factory game showing conveyor belts, a central Compact Splitter labeled 'Deliver 0 To Unlock', and a sidebar list of saved blueprint names.

In the screencap you can see resources of discs and squares and well as green and red, which are to be extracted, chopped up and recombined to form the "product" specified in the Hub.

Here's a sample of three different final "products" with multiple quadrants, layers, colours and shapes (all four shapes are at least partially represented here: a disc, star and windmill; a full square is only partially represented):
Screenshot of game UI showing a shape icon with a score of 0 out of 25k, and a second shape icon with a count of 876.1k.

I was lying awake last night, trying to figure out how many possible products there can be, and I kept getting intuitively wrong numbers.I'll start with the easy one. I'll enumerate only products that are fully rotationally symmetrical. i.e. all four quadrants of the deliverable product are identical. Thus:
Screenshot of a game icon: a circular emblem with a blue and grey stylised design, possibly a shape resource or logo, framed by a grey ring.

This is a blue windmill, on top of a white disc, on top of a blue disc.Parameters:

  • There are four primary shape resources: square, disc, star and windmill.
  • Each shape can have one of seven colours: R,G,B,C,M,Y and white.
  • And there can be up to four layers. (There is always a bottom later; if there is a second layer, it is on top of that; if there is a third later, it is on top of that, etc. There are no "empty" layers.)
  • (Size is not a parameter; rotational orientation is not a parameter.)

So, the number of (symmetrical) products should be 4x7x4 = 112. Is this right? Is this too low?Now we go to asymmetrical products:

Each quadrant of an asymmetrical product can have one quarter of any of the above, so:

1124, or about 157 million, right?I'm just not sure I've enumerated it correctly. I suspect I've done the layers wrong in the symmetrical step. It's not just x4, is it? Is it to the power of 4?
 
I’m assuming adjacent layers must be of a different color?

Also, can you put a square on top of a fan? It seems ordering matters too.
 
erobz said:
I’m assuming adjacent layers must be of a different color?
No.

I mean, it might be true, but that can be treated as an exception. There are likely many exceptions - combinations that have specious rules.
 
erobz said:
Also, can you put a square on top of a fan? It seems ordering matters too.
You can. There are products where the points of stars are all you can see behind a disc.

Higher layers are rendered smaller for this purpose, as seen in the examples, but that has no effect on combinations.

Five small icons in a row, each a grey circle with overlapping coloured shapes: green and yellow quarter-circle wedges, a red and green quarter-circle, a purple square with a white circle and crosshairs, and yellow circles with red star points.
 
Attachments
  • Five stacked icons on a light grey background, each a circle divided into quadrants by a cross: green-and-yellow with cat-like ears, a quarter-circle slice, a white circle on purple, and two yellow circles with red spiky star shapes behind them.
    1683573686212.png
    5.7 KB · Views: 161
e.g. a blue circle , on a blue circle , on a blue circle, etc... is a valid configuration?
 
erobz said:
e.g. a blue circle , on a blue circle , on a blue circle, etc... is a valid configuration?
Yes. It may not actually be called for, but that doesn't mean it isn't part of the set of all possible products. It is not categorically ruled out.

Note that - whether or not it's called for - I can still produce it if I choose. Pretty easily, in fact.
 
So 1, 2, 3, 4 layers are all good too? If so:

1 layer configurations ##4\cdot 7##

2 layer configurations ##\left( 4 \cdot 7\right)^2 ##

3 layer configurations ##\left( 4 \cdot 7\right)^3 ##

4 layer configurations ##\left( 4 \cdot 7\right)^4 ##

Total symmetrical configurations:

##28+28^2+28^3+28^4 = 637,420##
 
Last edited:
If you are going to try to find the number of configurations in general (each quadrant), its going to be a much worse combinatorics problem than that because of removing rotationally symmetric configurations...well over my head.

For single layer - single shape, is blue circle quad 1 distinct from blue circle quad 4?
 
Last edited:
erobz said:
If you are going to try to find the number of configurations in general (each quadrant), its going to be a much worse combinatorics problem than that because of removing rotationally symmetric configurations...well over my head.
Good point.
erobz said:
For single layer - single shape, is blue circle quad 1 distinct from blue circle quad 4?
No. That's what I meant by 'orientation is not a parameter'.
But I see why it can't be ignored, because ignoring it would let duplicates slip in.
 
erobz said:
Total symmetrical configurations: ##28+28^2+28^3+28^4 = 637,420##

So with ## n = (28^4 + 28^3 + 28^2 + 28)^4 = 637,420 ## quadrant types there are ## n ^ 4 = 165,083,148,768,756,940,960,000 ## possible permutations: if we divide this by 4 to get 41,270,787,192,189,235,240,000 we will eliminate rotations but we will have eliminated too many (for instance the unique permutation {type1, type1, type1, type1} will have been incorrectly "eliminated" 3 times) so the answer is a little over that. I make it 41,270,830,356,497,512,121,750: can you get this result or have I made a mistake?
 
pbuk said:
So with ## n = (28^4 + 28^3 + 28^2 + 28)^4 = 637,420 ## quadrant types there are ## n ^ 4 = 165,083,148,768,756,940,960,000 ## possible permutations: if we divide this by 4 to get 41,270,787,192,189,235,240,000 we will eliminate rotations but we will have eliminated too many (for instance the unique permutation {type1, type1, type1, type1} will have been incorrectly "eliminated" 3 times) so the answer is a little over that. I make it 41,270,830,356,497,512,121,750: can you get this result or have I made a mistake?
Removing rotational symmetry:

For a 1 layer 1 quadrant selection, there is only one configuration.

A 2x2 grid of four square tiles with black borders, where only the top-right tile is filled green and the other three are white.


There are then ##4\cdot7 = 28## ways to select a shape and a color.

For a 1 layer 2 quadrant selection, there are two configurations. Sides touching, corners touching.

Two 2x2 grids of square quadrants; green fills the top two squares in the left grid and the top-left and bottom-right squares in the right grid.


Thats ##2 \cdot \left( 4\cdot7 \right)^2 = 1,568##

For a 1 layer 3 quadrant selection, there is one configuration.

Diagram of a 2x2 grid of square tiles: the top-left, top-right and bottom-right squares are filled green and the bottom-left square is white.


Thats ##\left( 4\cdot7 \right)^3 = 21,952##

For a 1 layer 4 quadrant selection, there is one configuration.

A square divided into four equal quadrants by black lines, with all four quadrants filled in solid light green.


Thats ##\left( 4\cdot7 \right)^4 = 614,656##

Total 1st layer configurations - removing rotational symmetry ##638,204##, which is not ## \frac{\left( 4 \cdot 7\right)^4}{4} = 153,664##. So for the general case, I don't think that's working.

Also, I feel like there is a layer dependency issue to consider as well.

I think the possible configurations of the second layer, hinge on what configuration has been selected on the first layer? i.e. putting the blue layer on top of the green layer below would not be allowed?

Red prohibition sign: a circle with a diagonal slash from upper left to lower right, over a 3 by 3 grid of squares with a green quadrant and blue quadrants shown in a 2 by 2 arrangement.


But this would be valid.

A 2 by 2 grid of square quadrants: top-left white, top-right green, bottom-left white, bottom-right green, with blue squares overlaid on the top-left and bottom-right quadrants.


Maybe I'm misinterpreting that part.
 
Last edited:
erobz said:
I feel like there is a layer dependency issue to consider as well.
I think the clarifications in #5 and #7 implied that the layers are entirely independent.

erobz said:
putting the blue layer on top of the green layer below would not be allowed?

View attachment 326240
Why not?
 
pbuk said:
I think the clarifications in #5 and #7 implied that the layers are entirely independent.Why not?
I've probably misinterpreted this:
Parameters:

  • And there can be up to four layers. (There is always a bottom later; if there is a second layer, it is on top of that; if there is a third later, it is on top of that, etc. There are no "empty" layers.
But I can't see any example in #5 that clarifies that?

I guess that first one on the left does clarify that as a misinterpretation(I think).
 
Last edited:
Assuming there no interlayer dependency:

Then I think the total is the sum of all possible layer shapes and configurations:

##638,204+ 638,204^2 +638,204^3+ 638,204^4##

?

Its still not clear in my mind whether or not we need to remove a bunch of rotational symmetries in that. These problem quickly get me spinning in circles. My gut says the answer to that is certainly.
 
Last edited:
erobz said:
Assuming there no interlayer dependency:

Then I think the total is the sum of all possible layer shapes and configurations:

##638,204+ 638,204^2 +638,204^3+ 638,204^4##
No, you seem to be confused. The shapes are not composed of 1, 2, 3 or 4 layers each with 4 quadrants, they are composed of 4 quadrants each with 1, 2, 3 or 4 layers. You calculated the correct number of quadrant types in #8: see my extension of that calculation in #11.
 
pbuk said:
No, you seem to be confused. The shapes are not composed of 1, 2, 3 or 4 layers each with 4 quadrants, they are composed of 4 quadrants each with 1, 2, 3 or 4 layers. You calculated the correct number of quadrant types in #8: see my extension of that calculation in #11.
In the green shape in post #5 there is no first layer shape in the right side quadrants. The first layer in that shape is

Four-cell grid with a green quadrilateral shape in the left column, one piece in the upper left cell and one in the lower left cell, with the right-hand cells empty.


The next layer is:

Green filled circle inscribed in a square, with a black cross dividing the circle into four equal quadrants.


The third and final layer is:

Square divided into four equal quadrants by thick black lines, with the right half filled in gold by a semicircle whose curved edge bulges past the right side of the square.


Which makes:

Diagram of a green shape made of a circle with a green triangular wedge on the left, divided into quadrants by black lines, with a smaller yellow semicircle inside the right half.
 
erobz said:
In the green shape in post #5 there is no first layer shape in the right side quadrants. The first layer in that shape is

View attachment 326265
I see what you mean. That example shape seems to contradict the stated rules:
DaveC426913 said:
...There is always a bottom latyer ... There are no "empty" layers
@DaveC426913 where did you get the examples from? Edit: and where did you get the rules from?
 
Last edited:
OK, I have now played the (demo version of the) game: the examples are right, my interpretation of @DaveC426913's rules was wrong.

A shape consists of 1, 2, 3 or 4 layers.
No layer can be completely empty: at least one quadrant must have a part.
Rotational orientation DOES matter so we don't have to worry about eliminations.
So each quadrant of a layer can have any one of 4 shapes in any one of 7 colours, or no shape at all, except that the configuration with no shapes in any quadrant is not allowed.
Edit: That gives ## c = ((4)(7)+1)^4 - 1 = 707,280 ## configurations for a layer.
And with 1, 2, 3 or 4 layers with no interdependencies there are c + c^2 + c^3 + c^4 = 250,245,412,237,998,716,617,680 \approx 2.5 \times 10^{23} shapes in all.
That gives ## c = ((4)(8)+1)^4 - 1 = 1,185,920 ## configurations for a layer.
And with 1, 2, 3 or 4 layers with no interdependencies there are ## c + c^2 + c^3 + c^4 = 1,977,980,197,799,639,651,080,320 \approx 2.0 \times 10^{24} ## shapes in all.
 
Last edited:
erobz said:
In the green shape in post #5 there is no first layer shape in the right side quadrants.
Sunuvagun. You're right.
All the more foolish of me since I had just finished building that one.

pbuk said:
@DaveC426913 where did you get the examples from? Edit: and where did you get the rules from?
The examples are levels I've finished. The rules I am deducing. So yeah, I made a mistake there.
 
Last edited:
pbuk said:
Rotational orientation DOES matter so we don't have to worry about eliminations.
Not sure why you say this. As far as I am concerned, a final product that's rotated 90 or 180 degrees is the same product.

pbuk said:
in any one of 7 colours,
And I just discovered that no-colour (or grey) is a valid colour, so that makes 8.
 
DaveC426913 said:
Not sure why you say this. As far as I am concerned, a final product that's rotated 90 or 180 degrees is the same product.

But not as far as the game is concerned:
Statistics panel from a factory game showing the PRODUCED tab selected, with three shape tiles each marked 0.40 per second: a half-circle left quarter-shaded shape, a quartered circle, and a right half-circle shape.


Have you seen the shape generator? This shows that https://viewer.shapez.io?----CuCu is not the same as https://viewer.shapez.io?CuCu----.

DaveC426913 said:
And I just discovered that no-colour (or grey) is a valid colour, so that makes 8.
Of course: at the start of the (demo) game you only have grey. I have edited my calculation in #19.
 
Hm.
I must have the rules wrong because, with my understanding, this product should be impossible:

Diagram of a circular badge containing a square split into four quadrants, with two white quarter-circle shapes and two grey square cells arranged in a stepped layout.


This is how it says it is constructed (I have labeled the layers a and b for clarity):

Screenshot of a Layers panel with two labeled panels, a and b, each showing four quadrant corners with text labels and a central shape diagram.


Layer a must be the top layer. (smaller shape = higher layer.)

If I simply drop a on b, it will not form two layers; I know the rules are that, if it can combine two shapes into the same layer without overlap, it will do so.

So this should form a single layer and will look like this:
A circle-like icon split into four quarters, with two diagonally opposite quarters shaded grey and the other two white, outlined in dark grey.


Tricky...
 
Attachments
  • Screenshot of a LAYERS panel with two quadrant diagrams: the top shows a small gray square at center with corners labeled EMPTY, EMPTY, GRAY, EMPTY; the bottom shows a split circle with corners labeled WHITE, GRAY, EMPTY, WHITE, plus a COPY KEY button.
    1683759688831.png
    7.7 KB · Views: 199
I threw in my hat on this one. I went looking for hints on how to solve this type ans stumbled across the exact solution. Here it is in a compact, 2 cell-high format. I'd need to duplicate this about 50 times to get it to deliver in less than a few hours.

Simple Combo/Permute calculation
 
DaveC426913 said:
Hm.
I must have the rules wrong because, with my understanding, this product should be impossible:

View attachment 326326

This is how it says it is constructed (I have labeled the layers a and b for clarity):

View attachment 326328

Layer a must be the top layer. (smaller shape = higher layer.)

If I simply drop a on b, it will not form two layers; I know the rules are that, if it can combine two shapes into the same layer without overlap, it will do so.

So this should form a single layer and will look like this:
View attachment 326327

Tricky...
So you are finding that what I said in the bottom of post #12 to be the correct interpretation?
 
erobz said:
So you are finding that what I said in the bottom of post #12 to be the correct interpretation?
No, that's incorrect.
The samples at the bottom of post 12 are both legal.

I guess the rules need to be relaxed to merely "no layer can be placed on top of an empty layer."In fact, this one is quite simple:
Square grid diagram of a 2x2 arrangement: top-right cell green, bottom-left and top-left cells grey, and two overlapping blue 2x2 blocks offset in the centre.

It's just:
Two square grids of cells: left, a 2 by 2 grid with three grey cells and the top-right cell green; right, a 2 by 2 grid with the top two cells blue, bottom-left grey and bottom-right blue.

Even this is legal:

Diagram of three overlapping squares: a green square at top right, a blue square at left, and a blue square below the overlap, with the overlapping region shown in blue.

It's just:
Diagram of a green square beside a blue L-shaped tromino made of three blue squares, two in the top row and one below the right square.


But this one is tricky:
Diagram of a 2x2 grid of squares with three filled cells: top-left and top-right are green, bottom-left is blue, and bottom-right is green; the blue cell is offset down and left so it sits partly under the green cells.

If you simply stacked blue on top of green, you would actually get this:
Two-by-two grid of squares: the top two and the bottom-right square are green, and the bottom-left square is blue.

because it will "melt" together if it can.
 
Last edited:
DaveC426913 said:
No, that's incorrect.
The samples at the bottom of post 12 are both legal.

I guess the rules need to be relaxed to merely "no layer can be placed on top of an empty layer."
White squares represent "empty" spots in a layer in my diagrams. By what you stated in #23 I would expect:

Left: a crossed-out 4x4 nested grid of white, blue and green squares; right: an arrow pointing to a 2x2 arrangement with blue, green, white and blue squares, with a smaller blue square inside the green one.


?
 
erobz said:
White squares represent "empty" spots in a layer in my diagrams. By what you stated in #23 I would expect:
Unfortunately, white is a valid colour so you can't use white as null. And I recently found out that even the default grey is a valid colour. So, the way to represent null has to be to literally "not there at all".

Your shape is represented thus:
Diagram of a plus-shaped arrangement of four squares on a grid, with a blue square at left, a blue square at centre, a green square at top right and a blue square below the centre.

That is the case with the actual product I most recently built:
Square-cornered icon in a grey circle made of four quarter-cell tiles: top-left white quarter-circle, top-right grey square, bottom-left grey square, bottom-right white quarter-circle, outlined in dark grey.

(The grey circle is actually just the background "placeholder".)
 
DaveC426913 said:
Unfortunately, white is a valid colour so you can't use white as null. And I recently found out that even the default grey is a valid colour.

So, the way to represent null has to be to literally "not there at all".
I get that, but the diagrams that I'm creating to get on the same page as you for valid configs. "a white square is empty quadrant in a layer". Thus I am correct that the figure on the left would automatically convert to the figure on the right.

It has significant "structural" implications for how we would count. How may "colors" or "shapes" there actually are to chose from is trivial to the counting process.
 
erobz said:
I get that, but the diagrams that I'm creating to get on the same page as you for valid configs. "a white square is empty quadrant in a layer". Thus I am correct that the figure on the left would automatically convert to the figure on the right.
You are technically correct, but your choice of rendering is going to lead to misunderstandings, tears and heartbreak. Remember, we're not the only ones reading this thread. :wink: