Euclidean rhythm: Difference between revisions

Content added Content deleted
imported>CosmiaNebula
(javascript)
imported>CosmiaNebula
(python)
Line 17: Line 17:
* At this point, we can continue the algorithm until only one form remains, but notice that one of the groups has only one element [100], so the algorithm can actually terminate right here and output the concatenation 1001010010100.
* At this point, we can continue the algorithm until only one form remains, but notice that one of the groups has only one element [100], so the algorithm can actually terminate right here and output the concatenation 1001010010100.


== Javascript ==
== [[Python]] ==
{{trans|JavaScript}}<syntaxhighlight lang="python3">
def E(k, n):
s = [[1] if i < k else [0] for i in range(n)]

d = n - k
n = max(k, d)
k = min(k, d)
z = d

while z > 0 or k > 1:
for i in range(k):
s[i].extend(s[len(s) - 1 - i])
s = s[:-k]
z = z - k
d = n - k
n = max(k, d)
k = min(k, d)

return [item for sublist in s for item in sublist]

print(''.join(map(str, E(5, 13))))
# 1001010010100

</syntaxhighlight>

== [[:Category:JavaScript|JavaScript]] ==
Copied from [https://mrmr.io/mj/euclid here] and [https://github.com/mnvr/gm1k?tab=readme-ov-file here], under MIT license.<syntaxhighlight lang="javascript">
Copied from [https://mrmr.io/mj/euclid here] and [https://github.com/mnvr/gm1k?tab=readme-ov-file here], under MIT license.<syntaxhighlight lang="javascript">
const E = (k, n) => {
const E = (k, n) => {