What is a Euclidean Rhythm?
1. Start with a list of n ones (pulses) and k-n zeros (non-pulses). So if n=5, k=13 and your starting list is as follows:
2. Take the last n number of trailing zeros from the end of the list and group each one with the first n values (all ones at this point) in turn e.g.
1111100000000 -> 11111000 00000
3. This is repeated until non-pulses are grouped with pulses, like so:
11111000 11111 00000 -> 00000 000
4. In this example there are now two groups smaller than the others. Let's call these "spare" columns/groups. We do as we did previously, adding the trailing columns to the leading columns until we only have 1 or 0 "spare" columns
111 1 1 1 000 0 0 0 000 -> 0 0 0 -> 1001010010100 11 1 1 00 0 0
Programming a Euclidean Rhythm
The function below is written Python and returns the Euclidean Rhythm for any value of n and k (it returns k number of ones when n > k). I hope this is of use to some people. If you think the algorithm isn't quite right (I had to do a lot of figuring it out myself) or you think it can be made more efficient - please do let me know in the comments!
def Euclid(n, k):
data = [[1 if i < n else 0] for i in range(k)] while True: k = k - n if k <= 1: break elif k < n: n, k = k, n for i in range(n): data[i] += data[-1] del data[-1] return [x for y in data for x in y]