Jump to content

Euclidean rhythm: Difference between revisions

python
imported>CosmiaNebula
(javascript)
imported>CosmiaNebula
(python)
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.
 
== 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">
const E = (k, n) => {
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.