Skip to content

BinaryStrings ​

The 2n2^n binary strings of length nn, in standard binary counting order.

✓ checked against that system · ! checked, with disagreements (hover a chip)OEISA000079✓A320487✓A011782✓A131577✓A034008✓A166444✓
BinaryStrings(n)the binary strings of length nn
CombinatoricaMap[Function[s, Table[Boole[MemberQ[s, i]], {i, n}]], BinarySubsets[Range[n]]]
Typed signatures
TypePackageApplies
(integer<0..>) -> indexed_collection<list<integer>>combinatoricsalways

Domain: Collections

Definition

Epsil, as the implementation runs it.

count(_n)

1 if _n == 0 else 2 ^ _n

unrank(_n, _r)

Map(
     Function((_r - _r % 2 ^ (_n - j)) / 2 ^ (_n - j) % 2 + 0, j),
     Range(1, _n, 1),
   )

rank(_n, _x)

Fold(Function(acc * 2 + (_x[j] - 0), acc, j), 0, Range(1, _n, 1))

valid(_n, _x)

Length(_x) == _n && Fold(Function(
                                   ok_j && 0 <= _x[j] && _x[j] <= 2 + 0 - 1,
                                   ok_j,
                                   j,
                                 ), True, Range(1, Length(_x), 1))

Examples

Basic #

242^4 strings

live ↗
InCount(BinaryStrings(4))\mathrm{Count}(\mathrm{BinaryStrings}(4))Out1616

All of length 3, in counting order

live ↗
InTake(BinaryStrings(3),8)\mathrm{Take}(\mathrm{BinaryStrings}(3), 8)Out[[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]]\bigl\lbrack\bigl\lbrack0, 0, 0\bigr\rbrack, \bigl\lbrack0, 0, 1\bigr\rbrack, \bigl\lbrack0, 1, 0\bigr\rbrack, \bigl\lbrack0, 1, 1\bigr\rbrack, \bigl\lbrack1, 0, 0\bigr\rbrack, \bigl\lbrack1, 0, 1\bigr\rbrack, \bigl\lbrack1, 1, 0\bigr\rbrack, \bigl\lbrack1, 1, 1\bigr\rbrack\bigr\rbrack
About
Examples2
Checked againstCombinatorica 2 agree
CrosswalkOEIS ×6Combinatorica

Implementation

mappedcombinatoricapackages/oracle/src/mappings.ts

Combinatorica lists binary counting as subsets; the word of a subset has a 1 at each element.

See also: BinaryWords