Example Code

Enumerate A Choose B

Code and Documents

Attachment

Overview

Description

This is a simple little recursive vi that I made when I was messing around with a puzzle solving routine.  It takes 2 numbers as input (A and B) and returns an array of length: A!/B!/(A-B)!.  Each element in the array is a U32 number which defines, as a bitmask, every possible unique permutation of 'B' bits in a field of length 'A'.

Because the output is of U32 representation, the vi only accepts an input to A up to 32.  Be forewarned, however, that in the worst case scenario, 32 choose 16, the output array will contain over 600 million elements which is over 2 GB and the vi can take up to 90 seconds to complete.  (I crashed my computer running this worst case when I accidentally left retain wire values on.)  As long as you keep A at 26 and under, the vi should always run in less than a second.  The main use for this vi is to initialize For loops when you need to examine a combination of events.  Inside the for loop the number can be broken into its bit components. 

I'll be posting a few miscellaneous vi's like this over the next few days because I figured someone might use them.  If anyone finds an odd use for this one I would love to hear about it in the comments, thanks guys.

Here is an example program with the corresponding output:

achoosebcode.png

achooseb.png

Requirements

Software

Labview 2012 or Higher

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors