Math-DyckWords

 view release on metacpan or  search on metacpan

lib/Math/DyckWords.pm  view on Meta::CPAN

for the 0's an 1's listed above we have:

    ((()))
    ()(())
    ()()()
    (())()
    (()())

There is also a relationship between Dyck words and Catalan numbers.
Catalan numbers have many applications in combinatorics and consists
of a sequence of ever increasing integers following the formula:

    (2n)!/(n!(n+1)!)

The first few numbers in the Catalan sequence are:

    1, 1, 2, 5, 14, 132, 429, 1430, 4862, 16796, 58786, 208012

The relationship between Dyck words and the Catalan sequence can
be easily seen as the nth Catalan number is equal to the number of
permutations, or unique Dyck words of length 2n. For example,

lib/Math/DyckWords.pm  view on Meta::CPAN

    # discard the zeroth element of the list of positions
    shift @b;

    return translate_positions( @b );
}

=over

=item catalan_number( $n )

Using the formula - (2n)!/(n!(n+1)!) - this function returns the
corresponding number $n from the Catalan sequence.

=back

=cut

sub catalan_number( $ ) {
    my $x = shift;

    my $X = Math::BigInt->new( $x );



( run in 0.647 second using v1.01-cache-2.11-cpan-26ccb49234f )