N
N
nadom2015-10-08 01:17:52
ruby
nadom, 2015-10-08 01:17:52

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

5 answer(s)
J
Jeiwan, 2015-10-08
@Jeiwan

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.

R
Roman Mirilaczvili, 2015-10-08
@2ord

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.

N
nagibator8000, 2015-10-08
@nagibator8000

maybe 42?

P
pashablya1, 2015-10-09
@pashablya1

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 question

Ask a Question

731 491 924 answers to any question