Calculation of greatest common divisors is a quite complex problem for a digital computer, but not for pendulums:
The pendulums line up at the edge with frequencies given by the common divisors of their individual frequencies. For example, here is diagram of a 6Hz and a 4Hz signal, you can see that they line up with a frequency of 2Hz:
The algorithm it solves it is thought to be NP (it gets slow pretty quickly). Even though the problem it solves is difficult in the usual sense, the python code to calculate it is actually quite short (though I have deliberately made it so here):
def gcd(a,b):
return a if b == 0 else gcd(b, a%b)


