place vials in your centrifuge
Sage – 102 104/115

Why use number theory, when there is brute force?

v=lambda n:[j for j in range(n+1)if all(sum(e^(i*2*I*pi/n)for i in c)for c in Combinations(range(n),j))]


For a given number of vials, this goes over all ways to position the vials and calculates their center of mass by using complex arithmetics. If the center of mass is zero for none of these ways, the number is returned.

Unfortunately, this does not work in certain cases (10,14), because Sage fails to simplify some expressions to zero (which may be related to this bug). One could regard this as a flaw of the interpreter and not the program and still say that the algorithm and program are fine. 

The following 113-character alternative relies on floats instead of symbols and does not suffer from these problems:

v=lambda n:[j for j in range(n+1)if all(abs(sum(exp(i*2j*pi/n)for i in c))&gt;1e-9for c in Combinations(range(n),j))]




Test output of the 113-character version (for n in range(14): print n,v(n)):

0 []
1 [1]
2 [1]
3 [1, 2]
4 [1, 3]
5 [1, 2, 3, 4]
6 [1, 5]
7 [1, 2, 3, 4, 5, 6]
8 [1, 3, 5, 7]
9 [1, 2, 4, 5, 7, 8]
10 [1, 3, 7, 9]
11 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
12 [1, 11]
13 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
14 [1, 3, 5, 9, 11, 13]


I did not want to wait the runtime for higher n.



This originates from the following Python solution. Exact arithmetics and not having to import some modules is quite something.

Python – 173 154 156

from itertools import*
from cmath import*
v=lambda n:[j for j in range(n+1)if all(abs(sum(exp(i*2j*pi/n)for i in c))&gt;1e-9for c in combinations(range(n),j))]


Test output of this variant (for n in range(24): print n,v(n)):

0 []
1 [1]
2 [1]
3 [1, 2]
4 [1, 3]
5 [1, 2, 3, 4]
6 [1, 5]
7 [1, 2, 3, 4, 5, 6]
8 [1, 3, 5, 7]
9 [1, 2, 4, 5, 7, 8]
10 [1, 3, 7, 9]
11 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
12 [1, 11]
13 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
14 [1, 3, 5, 9, 11, 13]
15 [1, 2, 4, 7, 8, 11, 13, 14]
16 [1, 3, 5, 7, 9, 11, 13, 15]
17 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
18 [1, 17]
19 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
20 [1, 3, 17, 19]
21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20]
22 [1, 3, 5, 7, 9, 13, 15, 17, 19, 21]
23 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]
24 [1, 23]


I did not want to wait the runtime for higher n.