I've read the Godfried Toussaint's work, The Euclidean Algorithm Generates Traditional Musical Rhythms. This paper describes how is possible to generate percussive rhythms using an Euclidean algorithm and how many classical rhythms have a link with this principle.
The paper also cite the Björklund's work The Theory of Rep-Rate Pattern Generation in the SNS Timing System where an algorithm to distribute k pulses (1s) in n slots of time is presented and shows how this algorithm is bounded to the Euclidean principle.
I decided to translate the algorithm in Elixir.
The module has two public functions:
bjorklund(slots, pulses)
, returns a list that represents the sequence ofpulses
1s evenly distributed inslots
unitsis_evenly_distributed(seq)
, checks ifseq
is an evenly distributed sequence of 1s.
Here is an example usage (in iex):
iex(1)> Bjorklund.bjorklund 15, 6
[0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]
iex(2)> Bjorklund.is_evenly_distributed [1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0]
true
iex(3)> Bjorklund.is_evenly_distributed [0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0]
false