Input: radius R, size D
- Generate all integer sections from R with cardinality ≤ D
- Rearrange it for each section without repeating
- For each permutation, twist all the signs
For example, the code in python:
from itertools import * # we have to write this function ourselves because python doesn't have it... def partitions(n, maxSize): if n==0: yield [] else: for p in partitions(n-1, maxSize): if len(p)<maxSize: yield [1] + p if p and (len(p)<2 or p[1]>p[0]): yield [ p[0]+1 ] + p[1:] # MAIN CODE def points(R, D): for part in partitions(R,D): # eg 4->[3,1] part = part + [0]*(D-len(part)) # eg [3,1]->[3,1,0] (padding) for perm in set(permutations(part)): # eg [1,3,0], [1,0,3], ... for point in product(*[ # eg [1,3,0], [-1,3,0], [1,-3,0], [-... ([-x,x] if x!=0 else [0]) for x in perm ]): yield point
Demo radius = 4, size = 3:
>>> result = list( points(4,3) ) >>> result [(-1, -2, -1), (-1, -2, 1), (-1, 2, -1), (-1, 2, 1), (1, -2, -1), (1, -2, 1), (1, 2, -1), (1, 2, 1), (-2, -1, -1), (-2, -1, 1), (-2, 1, -1), (-2, 1, 1), (2, -1, -1), (2, -1, 1), (2, 1, -1), (2, 1, 1), (-1, -1, -2), (-1, -1, 2), (-1, 1, -2), (-1, 1, 2), (1, -1, -2), (1, -1, 2), (1, 1, -2), (1, 1, 2), (0, -2, -2), (0, -2, 2), (0, 2, -2), (0, 2, 2), (-2, 0, -2), (-2, 0, 2), (2, 0, -2), (2, 0, 2), (-2, -2, 0), (-2, 2, 0), (2, -2, 0), (2, 2, 0), (-1, 0, -3), (-1, 0, 3), (1, 0, -3), (1, 0, 3), (-3, -1, 0), (-3, 1, 0), (3, -1, 0), (3, 1, 0), (0, -1, -3), (0, -1, 3), (0, 1, -3), (0, 1, 3), (-1, -3, 0), (-1, 3, 0), (1, -3, 0), (1, 3, 0), (-3, 0, -1), (-3, 0, 1), (3, 0, -1), (3, 0, 1), (0, -3, -1), (0, -3, 1), (0, 3, -1), (0, 3, 1), (0, -4, 0), (0, 4, 0), (0, 0, -4), (0, 0, 4), (-4, 0, 0), (4, 0, 0)] >>> len(result) 66
(Above, I used set(permutations(...)) to get permutations without repeating, which is ineffective at all, but here it may not matter due to the nature of the points. And if efficiency mattered, you could write your own recursive function in your language of choice.)
This method is effective because it doesn’t scale with a hyperwave, but simply scales with the hypersurface you are trying to list (maybe it doesn’t matter much except for very large radii: for example, you will save about one factor 100x speed if your radius equal to 100).