Hi, I have recently approached a problem I had on cue for a long time, an Euclid divider.
What does an Euclid Sequence Generator does?
An Euclid Sequence Generator is an algorithm that distributes as even as possible 2 numbers in a sequence. So lets say that for example you want a sequence with a length of 12 with 5 pulses distributed as even as possible. So the approach would be as follows:
We need to know how many steps are off, so: (lenght - pulses) 12 - 5 = 7
Start with the following numbers:
7 - 0: 0 0 0 0 0 0 0
5 - 1: 1 1 1 1 1
having now 5 sequences of "01" and 2 sequences of "0" to distribute, so we are going to do the same but we are calling "01" -> a, and "0" -> b. We are going to iterate until max - min <= 1.
a = 01; b = 0;
5 - a: a a a a a
2 - b: b b
doing another iteration:
x = ab; y = a;
3 - y: y y y
2 - x: x x
p = yx
q = y
In here max - min is 1 so in this iteration we can create our sequence:
p-p-q
(yx)-(yx)-(y)
([a][a.b])-([a][a.b])-([a])
([01][01.0])-([01][01.0])-([01])
the sequence would be 010100101001 being a sequence o 12 y 5 pulses evenly distributed.
Take in mind that this pseudo algorithm is only to explain functionality, there are several things to do to do this more efficiently.
you can skip steps as with a Greatest common divisor algorithm ( by swapping "max - min" to "max % min"):
for example:
str_a = 1;
str_b = 0;
a = 5;
b = 2;
x = a/b = 2;
y = a%b = 1;
str1 = str_b + (str_a * x) = 011
output = (str1 * b) + str_a = 011 011 0
Now my next step is taking this to the next level by trying to distrubute more numbers in a sequence.
Lets say that you want a sequence with a length of 12, and have 5 a's , 4 b's and 3 c's distributed as evenly as possible, how would you people approach this problem?? I am interested in your opinion