Skip to content

Instantly share code, notes, and snippets.

@iani
Created June 2, 2015 10:04
Show Gist options
  • Select an option

  • Save iani/ebf111d14b34bf6e66b1 to your computer and use it in GitHub Desktop.

Select an option

Save iani/ebf111d14b34bf6e66b1 to your computer and use it in GitHub Desktop.
Re-order a list in level-order (breadth-first traversal), in SuperCollider, using recursion
(
f = { | list |
if (list.size == 0) {
[]
}{
list.collect({ | x | (if (x.size > 0) { x[0] } { x })})
++ f.(list.select ({| x | x.size > 0}).collect ({|x| x [1..]})
.select ({|x| x.size > 0}));
}
}
)
//: Tests:
f.([[1], [5], 3]);
// ================================================================
//:
f.([[1, 2], [5, 6, 7], 3]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment