Jump to content

Euclidean rhythm: Difference between revisions

added Phix
(Add MATLAB implementation)
(added Phix)
Line 355:
</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]] ==
7,813

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.