Brian Dunning's FileMaker Custom Functions

GetPatternList ( RC ; nObj ; n )

List of decimal numbers whose binary form contains the same number of bits set to 1

  Average rating: 4.4 (23 votes) Log in to vote

Erich Schmidt   Erich Schmidt

Share on Facebook Share on Twitter

  Sample input:
GetPatternList("";5;2)
GetPatternList("";6;3)
  Sample output:
24¶20¶18¶17¶12¶10¶9¶6¶5¶3 [all binary patterns with two bits set to 1]
56¶52¶50¶49¶44¶42¶41¶38¶37¶35¶28¶26¶25¶22¶21¶19¶14¶13¶11¶7 [... with three bits set to 1]

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

The function returns a list of decimal values in descending order, whose binäry form has exactly n bits set to 1.

The list can be used to get all subsets with n elements from a character set with nObj elements.

Assumed it is TEXT="AXTVBC", the call

Let ( [ $MyList = GetPatternList("";Length(TEXT); 3) ] ; CustomList ( 1 ; ValueCount ( $MyList ) ; "Combine ( GetValue ( $MyList ; [n] ) ; TEXT )" ) )

returns a list containing all subsets from "AXTVBC" with 3 elements, so

AXT¶AXV¶AXB¶AXC¶ATV¶ATB¶ATC¶AVB¶AVC¶ABC¶XTV¶XTB¶XTC¶XVB¶XVC¶XBC¶TVB¶TVC¶TBC¶VBC





Requires other CF: NextBinPattern()

Getting the right result requires a function call on the first recursion level with an empty RC-parm (RC="")

 

Comments

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Under construction. Email me your wish list for improvements.