Reorder Node

john's Avatar

john

30 Jan, 2025 09:31 AM

The Cartan Node Library is having a growth spurt. Here is yet another new node...

Reorder takes a list of up to 7 items and reorders it. The items can be anything: strings, numbers paths, points, colors, whatever. If you give it more than seven items it will only work with the first seven.

A limit of seven may seem restrictive, but there are 5040 different ways of reordering seven items. I have found a frequent need to reorder lists of only three or four items. For example, my Sanzo_colors node can output quartets of color and I often want to step through the 24 possible ways of reordering such a quartet.

It's a simple node. Just feed it your list and tell it which ordering you want:

  • Order 0 returns the list in its original order.
  • Order 1 returns the first permutation, order 2 the second, etc.
  • There are n! (n factorial) different possible orders for a list with n items. If you enter an order number greater than the possible number of permutations, reorder will return the final permutation.
  • If you give it a list with a single item it will just return that item

The attached demo shows the reorder node receiving strings, numbers, shapes, and colors. Change the value of the integer node named ORDER to see different permutations of those objects.

I also include a subnetwork with reorder inside it that produces a chart showing the 24 different ways of reordering four colored shapes.

Note: in the process of developing this node, I updated an earlier node, orderings, which lives inside the reorder node. The original version of orderings would only accept lists of from 3 to 8 items. The updated version accepts lists of from 1 to 7 items and runs noticeably faster. I will include the updated version of orderings in the next release of my library; if you need it before then you can pluck it from inside the reorder node.

If you want to visit my Instagram account you can see a nifty animation I made using reorder earlier today,

Enjoy!

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • reorder_screenshot.png 673 KB
  • reorder_node.ndbx.zip 174 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

06 Feb, 2025 01:37 AM
04 Feb, 2025 06:32 AM
04 Feb, 2025 05:04 AM
30 Jan, 2025 09:31 AM
30 Jan, 2025 09:08 AM

 

30 Jan, 2025 08:40 AM
24 Jan, 2025 07:50 AM
22 Jan, 2025 11:42 PM
21 Jan, 2025 09:43 AM
21 Jan, 2025 09:41 AM
21 Jan, 2025 09:36 AM