We have two infinitely repeating messages consisting of characters $a-z$. Each character takes a different amount of time units to transmit; $a=1, b=2, c=4, d=8,e=16 ...$, character | tells us current position in the message. Our job is to say how many units of time it will take to synchronize the two messages. Synchronization means that both messages begin at the same time.
Example:
We have message 1: $ea|babab$
and message 2: $d|abaca$
therefor we know that message 1 is $bababea$ and message 2 is: $abacad$.
The messages will be synchronized in 42 units of time: $$ ea|bababea| = 42 $$ $$ d|abacad|abacad| = 42 $$
Example 2: message1: $|acabbaaa$ message 2: $|dcbabaaaa$.
Solution: $0$, because they are already synchronized.
We want to come up with an algorithm which will calculate the time until first synchronization occurs.
I think this could maybe be done using extended Euclidean algorithm.