Euclidean rhythm: Difference between revisions
Content added Content deleted
(Add MATLAB implementation) |
(added Phix) |
||
Line 355: | Line 355: | ||
</pre> |
</pre> |
||
=={{header|Phix}}== |
|||
<syntaxhighlight lang="phix"> |
|||
function Euclidean_rhythm(integer k, n) |
|||
integer d = n - k, z = d |
|||
sequence s = repeat("1",k) & repeat("0",d) |
|||
n = max(k, d) |
|||
k = min(k, d) |
|||
while z > 0 or k > 1 do |
|||
string last = s[$] |
|||
for i=1 to k do |
|||
s[i] &= last |
|||
end for |
|||
s = s[1..-k-1] |
|||
z -= k |
|||
d = n - k |
|||
n = max(k, d) |
|||
k = min(k, d) |
|||
end while |
|||
return join(s,"") |
|||
end function |
|||
?Euclidean_rhythm(5,13) |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
"1001010010100" |
|||
</pre> |
|||
== [[Python]] == |
== [[Python]] == |