Suppose we have a bunch of radio stations, and each radio plays the same song over and over again on the loop. Can I sync all songs from all radio stations? Can we find a time when we hear all the songs from the start?
For simplicity, we will say that we have only two radio stations.
I have the following formulas:
c and z represent the length of the song in seconds. a and x represent the current position in the song (in seconds) S represents the synchronization time of C and Z. (When both songs start at the same time)
For example:
Song 1 a = 17 : the time before the song ends. b = 8 : the rest of the song. c = a + b which is the full song in seconds. And Song 2 x = 8 : the time before the song ends. y = 9 : the rest of the song. z = 8 + 9 which is the full song in seconds. Song 1 : a + ( a + b) => S Song 2 : x +(( x + y ) Γ n) => S Song 1 : 17 + ( 17 + 8) => 42 Song 2 : 8 + ((8 + 9)) = 25 So in order to synchronize song 2 with song 1 we have to multiply (x + y) by two and add x to it. Song 2 : 8 + ((8 + 9) x 2) => 42 So S = 42 and so the two songs will synchronize after 42 seconds.
Now this first example is the simplest. For other cases, I would have to multiply z and c by more than two to get the corresponding S.
I have a few other inputs, and I tried to come up with an algorithm that would return S to me, but I had no luck with that.
Here is what I came up with so far:
c = a + b a = 16 b = 4 c = 20 s = 216
and
z = x + y x = 12 y = 5 z = 17 s = 216 S is the LCM of c and z
In the first example, S was found as follows:
s = x +(z Γ n) n = ( s β x ) Γ· b 12 + ( 17 Γ 12) = 216
and
s = a + (c Γ n) n = ( s β a ) Γ· b 16 + ( 20 Γ 10 ) = 216
I came up with two formulas below. Based on the value of S. But I need to figure out a way to search for n without actually using S. Or, in other words, I need to find out how many times I have to multiply (a + b) by n and (x + y) by n to get S.
n = ( s β a ) Γ· b S = x + ( y Γ n)
But these formulas obviously will not work because they require S. And we cannot use this because it must be the result of the formula that I am trying to come up with.
Here are some examples for some calculations:
a2 = 52 b2 = 4 c2 = 56 s2 = 276 x2 = 60 y2 = 12 z2 = 72 s2 = 276
Here is a situation where it will never be synchronized:
A1 = 14 B1 = 4 C1 = 18 S1 = Never synchronizes A2 = 19 B2 = 5 C2 = 24 S2 = Never synchronizes
And here is a situation where the songs are already in sync:
Case 1
A2 = 17 B2 = 0 C2 = 17 S4 = 0 A3 = 25 B3 = 0 C4 = 25 S4 = 0
Case 2
A4 = 0 B4 = 13 C4 = 13 S4 = 0 A5 = 0 B5 = 21 C5 = 21 S5 = 0
I was thinking about using the least common plural, but I'm not sure how to implement it in this situation or if this is the right solution for this problem.
The algorithm I want to find should also work if there are more than two songs. For example, finding S for 3 or 4 songs.
The main problem with this algorithm is to solve two songs Synchronize or not, the calculation itself is not so complicated. could you help me? thanks in advance