Euclidean rhythm: Difference between revisions

Add Dart implementation
(Add Perl implementation)
(Add Dart implementation)
Line 16:
** 10010 10010 100 |
* 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.
 
 
=={{header|Dart}}==
{{trans|Python}}
<syntaxhighlight lang="Dart">
List<int> E(int k, int n) {
List<List<int>> s = List.generate(n, (i) => i < k ? [1] : [0]);
 
int d = n - k;
n = k > d ? k : d;
k = k < d ? k : d;
int z = d;
 
while (z > 0 || k > 1) {
for (int i = 0; i < k; i++) {
s[i].addAll(s[s.length - 1 - i]);
}
s = s.sublist(0, s.length - k);
z -= k;
d = n - k;
n = k > d ? k : d;
k = k < d ? k : d;
}
 
return s.expand((sublist) => sublist).toList();
}
 
void main() {
print(E(5, 13).join());
// Expected output: 1001010010100
}
</syntaxhighlight>
{{out}}
<pre>
1001010010100
 
</pre>
 
=={{header|EasyLang}}==
338

edits