Colour Sequencing / Combinatorics Tool

Caitlin needed a tool for creating lists of every possible combination of a set of variables (including the ability to limit the list length) so I wrote her a quick command line tool for doing that. She’s using it to output lists of every combination of yarn to make sure that every panel in a quilt-like thing (watch for it here in the future perhaps). Here’s how it works:

SEQUENCES
Note: you can also enter your variables on the command line, comma separated
Enter your variables now:
-->red,green,blue,black
Depth limitation? (Blank for no)
-->3
red, green, blue
red, green, black
red, blue, green
red, blue, black
red, black, green
red, black, blue
green, red, blue
green, red, black
green, blue, red
green, blue, black
green, black, red
green, black, blue
blue, red, green
blue, red, black
blue, green, red
blue, green, black
blue, black, red
blue, black, green
black, red, green
black, red, blue
black, green, red
black, green, blue
black, blue, red
black, blue, green

<press any key to exit>

So it outputs every possible combination, with order being important, with no repetition of colour inside the set, with the length of list limited as you desire (if at all). You can run it either by clicking it or running it from a prompt, or you can enter the list as the command line variables and redirect it to a file since it writes to stdio.

Source code* (PBCC) is included; download it here:
http://www.zentastic.com/code/sequences.zip [12k]

* It’s actually a useful piece of code for people looking to learn about how to write recursive software… this type of combinatorial processing is a great use for recursion. I should mention that the length limitation is a kind of sloppy add-on that uses global variables which is kind of frowned upon.

One Comment

  1. Thank you! I love you and your giant brain.

    Tuesday, April 29, 2008 at 7:35 pm | Permalink
Wow Shannon, that's really annoying! What is it, 1997 on Geocities? Retroweb is NOT cool!

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*