I am running the following code. It works for smaller NumberOfVariables, but not for any for 8 or larger due to lack of memory. I really just need the first AllAnswers that does not contain zero, but would like all AllAnswers if possible.
NumberOfVariables = 9;
k=NumberOfVariables^2-NumberOfVariables+1;
integers = 0:k-1;
numbers = 1:k-1;
tic
s = combnk(integers,NumberOfVariables);
AllAnswers = [];
for i = 1:size(s,1)
G=combnk(s(i,:),2);
G = [(G(:,1)'-G(:,2)') (G(:,2)'-G(:,1)')];
G = sort(mod(G,k));
if (isequal(G,numbers))
AllAnswers = [AllAnswers;s(i,:)];
end
end
toc
s = combnk(integers,NumberOfVariables);
Is the list of all Number of Variables
-sized combinations of elements in integers
. So that's a list with
k!/((NumberOfVariables!(k-NumberOfVariables)!)
or, since k = NumberOfVariables^2-NumberOfVariables
(NumberOfVariables^2-NumberOfVariables)!/((NumberOfVariables!(NumberOfVariables^2-2*NumberOfVariables)!)
using x for NumberOfVariables, to keep this readable:
(x²-x)! x²! x²! x²!
#s= ---------- > ---------- > ------------ = ------------
x!(x²-2x)! x!(x²-2x)! x!(x²-2x+1)! x!((x-1)²!)
you get the idea. this thing is not your friend if you're actually approaching it by allocating memory for #s elements. In fact, looking at this, for x>=4, this will grow faster than e^x.
For NumberOfVariables starting at 10, that simply gets incredibly large.
Do the math!
https://www.wolframalpha.com/share/clip?f=d41d8cd98f00b204e9800998ecf8427euo0stpao37
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.