Answer the question
In order to leave comments, you need to log in
What does the following code calculate?
At the same time, I'm trying to figure it out myself, but suddenly someone is familiar with the language. I google every method.
a = 2187
v = ->(x){(0..2).to_a.repeated_permutation(x)}
v[a].map do |r|
f,l = [-1],0
(1..2*a).each do |j|
i = f[j-l-1]
while i != -1 && r[j%a] != r[(l+i+1)%a]
l = j-i-1 if r[(l+i+1)%a] > r[j%a]
i = f[i]
end
if i == -1 && r[j%a] != r[(l+i+1)%a]
l = j if r[(l+i+1)%a] > r[j%a]
f[j-l] = -1
else
f[j-l] = i+1
end
end
r.rotate(l)
end.uniq.count do |r|
v[7].count{|s|(0...a).map{|l| r.rotate(l)[0,7]}.include?(s)} == a
end
Answer the question
In order to leave comments, you need to log in
Some complex calculations are going on here. Without context, or without knowledge of the relevant mathematical algorithms, it is difficult to understand. It's like generating a huge matrix and processing it.
It looks like the result of an obfuscator, to be honest.
Not so much complex calculations as highly confusing. Maybe linear algebra or discrete mathematics.
There are such metamorphoses in the code that it’s even scary to imagine why this is necessary
. If this is real code, such a developer needs to unscrew his hands.
It is also possible that the code is needed to waste computing resources.
nadom , can you help? how is the graph given here if it is a problem of finding a Hamiltonian cycle?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question