Find the order (size) of the symmetry group of a finite set of integer points in d-dimensional space.
Input
You will be given the coordinates of a finite set of points in d-dimensional space, in any reasonable form. The dimension d may be any positive integer. You can assume that all coordinates are integers, and that all points are distinct. You can optionally take d itself and/or the number of points as additional parameters.
Output
Output the number of symmetries of the set of points. A symmetry is an isometry of d-dimensional space that maps the set to itself (such as a reflection or a rotation). An isometry can be described by an orthogonal matrix A and a vector b, where a point x is mapped to Ax+b. The number of symmetries is always at least 1 (the identity map). The answer might be infinity, for which you must output any one consistent value that is not a positive integer (such as 0
or -1
or the string "infinity"
). The symmetries form a group (but you only need to output its size).
Note that it is not enough to count permutations of the points that preserve distances, because several isometries can give the same permutation (see examples below).
Examples
(0,0),(1,0),(1,1) -> 2
(0,0),(2,1) -> 4
(0,0),(1,0),(0,1),(1,1) -> 8
(1,1),(-1,-1),(1,-1),(-1,1) -> 8
(0,0),(1,0),(0,2) -> 1
(0,0) -> infinity
(0,5,0),(1,2,3) -> infinity
(0,0,0),(1,1,1),(2,2,2),(3,3,3) -> infinity
(0,0,5),(1,0,5),(0,1,5),(1,1,5) -> 16
(1,0,0),(0,1,0),(0,0,1) -> 12
(2,0,0),(0,2,0),(0,0,2),(2,1,0),(0,2,1),(1,0,2) -> 3
(1,1,1,1),(1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1) -> 24
(0),(1),(2) -> 2
(0),(1),(3) -> 1
(1) -> 2
Selected explanations
(0,0),(1,0),(0,1),(1,1)
is a square: the symmetries are 4 reflections (about diagonals and center-lines), 3 rotations, and the identity, making 8.
(0,0,5),(1,0,5),(0,1,5),(1,1,5)
adds a constant 3rd coordinate, so each symmetry of the square can in addition be composed with a reflection in the 3rd coordinate, giving 16 symmetries.
(0,5,0),(1,2,3)
: endpoints of a line segment. In 3 dimensions the line can be rotated by any angle, giving infinitely many symmetries.
This is code-golf. Shortest answer in each language wins.
(1)
infinity instead of 2? \$\endgroup\$(1)
case what are the symmetries other than \$x \rightarrow x\$ and \$x \rightarrow -x+2\$? Also(1,1,1,1),(1,0,0,0),(0,1,0,0),(0,1,0,0),(0,0,0,1)
should have(0,0,1,0)
instead of the second(0,1,0,0)
\$\endgroup\$