CMB(1)

NAME
cmb - combinatorics utility

SYNOPSIS
cmb [-0DefNorStvz] [-c num] [-d str] [-F num] [-i num] [-k size] [-n num] [-P num] [-p str] [-s str] [-X op] [item ...]

DESCRIPTION
The cmb utility prints combinations, one per line (default), with items in each combination separated by space (default). Given N items on the command-line, there are N sets where each set consists of an increasing number of items (default). By default, all sets are produced (‘-k 0’). Combination order within a set of N-items is always consistent and repeatable given the order of items on the command-line. The order of combinations within a single set of N-items (where every combination in the set has the same number of items) is dependent upon the order of items on the command-line.

Available options:

-0  Change the behavior of ‘-f’ to read items separated by NUL character (character code 0) instead of newline.

-c num
    Produce at-most num combinations. If ‘0’ (default) all combinations produced. Ignored when given ‘-t’.

-D  Enable debugging information on stderr. See cmb(3).

-d text
    Delimiter for separating items. Default is space (“ ”). Ignored when given ‘-t’.

-e  Show empty set. A single combination containing no-items.

-F num
    Find ‘-X op’ values that equal num. Requires ‘-X op’.

-f  Treat each command-line argument as a file containing items, one item per line (default). With ‘-0’, read items separated by NUL character. If an argument is ‘-’, read from stdin. The sum of items read from all files cannot exceed 4294967295.

-i num
    Skip the first num-1 combinations. If num is negative, skip to |num| combinations before the end. If num matches ‘random’ (case-sensitive) a random number between 1 and the total number of combinations is chosen. Ignored when given ‘-t’.

-k size
    Number or range ("min..max" or "min-max") of how many items must appear in each combination. A value of ‘0’ (default) calculates all sets starting with 1-item combinations. If size is negative one (-1), calculate sets in descending order, starting with the maximum number of items. A range of ‘-1..N’ will do the same but stop at N-item combinations. A range of ‘N..-1’ will start with N-item combinations and end with the maximum number of items. The order of combinations in each set is unaffected by negative size values. A range of ‘-1..-1’ calculates the ending set consisting of only the maximum number of items.

-N  Show combination sequence numbers. Combinations are calculated in arithmetic progression, providing predictable order. The sequence number can be used as a value to ‘-i num’ to start at that combination. Ignored when given ‘-t’.

-n num
    Limit the number of arguments taken from the command-line. No effect if num is greater than the number of arguments.

-o  Disable OpenSSL bn(3) support (limits calculations to 64-bits). No effect if unsupported. Use ‘-v’ to check OpenSSL support. The default is to use OpenSSL when supported. Must appear before ‘-c num’ and ‘-i num’ options.

-P num
    Change the behavior of ‘-X op’ to use num units of precision when printing floating point results. Default behavior of ‘-X op’ is to use the highest precision of provided arguments. Ignored when given ‘-t’.

-p text
    Prefix each combination with text. Ignored when given ‘-t’.

-q  Quiet. Do not print items from set when given ‘-X op’.

-r  Treat each command-line argument as a number or range to be expanded. If a single number, expand to numbers 1 to num. If a range ("min..max" or "min-max"), expand to numbers min to max. Numbers must be whole positive integers between 0 and 4294967295.

-S  Silent. Do not print combinations to stdout. Used with time(1) to determine stdio(3) overhead. With ‘-t’, do not print result.

-s text
    Suffix each combination with text. Ignored when given ‘-t’.

-t  Print total number of combinations and exit.

-v  Print version information to stdout and exit. Includes cmb(3) library version and (if-enabled) SSL(3) library version.

-X op
    Perform math on items where op is ‘add’, ‘subtract’, ‘divide’, or ‘multiply’ (case-sensitive). Argument op can be shortened to its minimally distinct representation; such as ‘a’ for ‘add’. Ignored when given ‘-t’.

-z  Print combinations followed by ASCII NUL character (character code 0) instead of newline (character code 10). With ‘-t’, do not print a trailing character after the result.

EXAMPLES
Print all two-word combinations ("bird dog", "bird house", and "dog house") given "bird", "dog", and "house":

    cmb -k 2 bird dog house

Print number of combinations (7) given "a", "b", and "c":

    cmb -t a b c

Print first 5 combinations ("x", "y", "z", "x y", and "x z") given "x", "y", and "z":

    cmb -c 5 x y z

Skip first 3 combinations ("x", "y", and "z") given "x", "y", and "z":

    cmb -i 4 x y z

Print last 5 combinations ("z", "x y", "x z", "y z", and "x y z") given "x", "y", and "z":

    cmb -i -5 x y z

Print items separated by comma instead of space:

    cmb -d , a b c

Print numbers as JSON:

    cmb -p '{"values":[' -s ']}' -d , 1 2 3

Print strings as JSON:

    cmb -p '{"values":[' -s ']}' -d , '"a"' '"b"' '"c"'

Print all 2- and 3-word combinations ( "big blue", "big red", "big couch", "blue red", "blue couch", "red couch", "big blue red", "big blue couch", "big red couch", and "blue red couch") given "big", "blue", "red", and "couch":

    cmb -k 2..3 big blue red couch

Print combinations starting with the maximum number of items (3), ending with 2-item combinations:

    cmb -k -1..2 1 2 3

Print combinations starting with 2-items ending with maximum items (3):

    cmb -k 2..-1 x y z

Roll a set of 2 six-sided dice, producing a single random combination of two numbers:

    cmb -c 1 -k 2 -i rand -r 6 6

Find all combinations of numbers 1, 2, and 3 that produce the sum of 4:

    cmb -X add -F 4 -r 3

HISTORY
The cmb utility first appeared in FreeBSD 13.0.

AUTHORS
Devin Teske <dteske@FreeBSD.org>