Today's new node is a node I thought I had made last summer: orderings.
Orderings returns a list of all the possible ways you could arrange n items. Each ordering is a comma-separated list of item indices.
For example, if n = 3, the possible orderings are:
- 0, 1, 2
- 0, 2, 1
- 1, 0, 2
- 1, 2, 0
- 2, 0, 1
- 2, 1, 0
One challenge with this node is that the number of possible orderings grows really fast: n factorial:
- 3 items have 6 orders
- 4 items have 24 orders
- 5 items have 120 orders
- 6 items have 720 orders
- 7 items have 5,040 orders
- 8 items have 40,320 orders
By 8 items, NodeBox starts to puff and pant, so I set an upper limit of 8 for the value of n.
The attached demo and screenshot show one example. I made a subnetwork called "trigram" which makes a shape consisting of a triangle, square, and pentagon glued together. The only difference in the output is in the order in which those three polygons are added: the first goes in the center, the next along its edges, the last as small bumps on the outside. The orderings node supplies the six possible orderings of three items.
The demo also contains a second example which lets you step through all 24 possible orders of four colors. It includes a reorder node that puts any list into a supplied comma-separated order.
I thought I had included this node with the combinatorics toolkit I released last summer, but I did not, so am rectifying that now. It was an interesting challenge making this node in Nodebox.
Comments welcome as always!