# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Find the rank of a totally balanced binary sequence

Contributed by:
Ed Pegg Jr

ResourceFunction["CatalanRank"][ returns the position of the given totally balanced binary sequence |

A binary sequence is considered totally balanced if the number of zeros is at least as large as the number of ones as one progresses from left to right in a list of zeros and ones, and the total counts are equal (implying the first element must be zero and the last element one).

The value returned is an index into a certain ordering of the set of all possible balanced sequences with *n* zeros and *n* ones, with indexing starting at 0.

The indexing scheme can be inverted using the resource function CatalanUnrank.

Brackets in a computer program must be balanced. One can think of a proper bracketing as having left brackets corresponding to zeros and right brackets to ones in a balanced binary sequence.

Find the rank of a given balanced binary sequence:

In[1]:= |

Out[1]= |

Find all totally balanced binary sequences of length 10:

In[2]:= |

Out[2]= |

Find the Catalan rank of each balanced sequence:

In[3]:= |

Out[3]= |

- 1.0.0 – 07 December 2020

This work is licensed under a Creative Commons Attribution 4.0 International License