> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/e/euclidean_rhythm.md).

# Euclidean rhythm

```ruby
func e(k, n) {
    var s = (^n -> map { |i| i < k ? [1] : [0] })

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

    while ((z > 0) || (k > 1)) {
        k.times { |i|
            s[i] += s[-1 - i]
        }
        s = s.first(-k)
        z -= k
        d = (n - k)
        n = max(k, d)
        k = min(k, d)
    }

    s.flat.join
}

say e(5, 13)
```

#### Output:

```
1001010010100
```
