Package young :: Module combination
[show private | hide private]
[frames | no frames]

Module young.combination

library for permutation and combination
Function Summary
  catalan(num)
catalan(n) -> Return the Catalan number
  catalan_generator()
catalan_generator() -> Return the Catalan number as a generator.
  combination(first, second)
combination(n, m) -> Return the combination of (n,m).
  factorial(x, y)
factorial([m=1), n) -> Return the factorial of n.
  k_composition(n, k)
k_composition(n, k) -> Return the number of k-composition of n.
  permutation(*seq)
permutation(sequence) -> Return the permutation of sequence
  weak_k_composition(n, k)
weak_k_composition(n, k) -> Return the number of weak k-composition of n.
  _combination_of_integer(big, small)
combination of two integers.
  _combination_of_sequence(seq, num)
out of the sequence, take num elements
  _mul_of_iterable(iterable, initial_value)
Return the multiply of iterable.
  _test()
  com_gen(seq, k)
Generate all combinations of k elements from the seq.
  half_perm_gen(seq)
generate half of all permutations from a given sequence.
  perm_gen(seq)
generate all permutations from a given sequence.
  permhalf(seq)

Function Details

catalan(num)

catalan(n) -> Return the Catalan number
>>> for i in range(10):
...     print catalan(i)
...

1
1
2
5
14
42
132
429
1430
4862

catalan_generator()

catalan_generator() -> Return the Catalan number as a generator.
>>> g = catalan_generator()
>>> for i in range(10):
...     print g.next()
...

1
1
2
5
14
42
132
429
1430
4862

combination(first, second)

combination(n, m) -> Return the combination of (n,m). n can be a sequence or an integer; m must be an integer.

If n is an integer, return the combination of (n, m) If n is a sequence, take m elements out of the sequence.
>>> n = 5
>>> for i in range(n):
...     print combination(n, i)
...

1
5
10
10
5
>>> s = 'abcd'
>>> for i in range(len(s) + 1):
...     print combination(s, i)
...

[[]]
[['a'], ['b'], ['c'], ['d']]
[['a', 'b'], ['a', 'c'], ['a', 'd'], ['b', 'c'], ['b', 'd'], ['c', 'd']]
[['a', 'b', 'c'], ['a', 'b', 'd'], ['a', 'c', 'd'], ['b', 'c', 'd']]
[['a', 'b', 'c', 'd']]

factorial(x, y=0)

factorial([m=1), n) -> Return the factorial of n.

If m is given, multiply an iterable from m to n. i.e., m x (m+1) x ... x n
>>> for i in range(10):
...     print factorial(i)
...

1
1
2
6
24
120
720
5040
40320
362880

k_composition(n, k)

k_composition(n, k) -> Return the number of k-composition of n.
>>> n = 5
>>> for i in range(n):
...     print k_composition(n, i+1)
...

1
4
6
4
1

permutation(*seq)

permutation(sequence) -> Return the permutation of sequence
>>> seq = range(3)
>>> for x in sorted(permutation(seq)):
...     print x
...

[0, 1, 2]
[0, 2, 1]
[1, 0, 2]
[1, 2, 0]
[2, 0, 1]
[2, 1, 0]
>>> permutation(seq) == permutation(*seq)
True

weak_k_composition(n, k)

weak_k_composition(n, k) -> Return the number of weak k-composition of n.
>>> n = 5
>>> for i in range(n):
...     print weak_k_composition(n, i+1)
...

1
6
21
56
126

_combination_of_integer(big, small)

combination of two integers.

_combination_of_sequence(seq, num)

out of the sequence, take num elements

_mul_of_iterable(iterable, initial_value=0)

Return the multiply of iterable.

com_gen(seq, k)

Generate all combinations of k elements from the seq.

half_perm_gen(seq)

generate half of all permutations from a given sequence.

perm_gen(seq)

generate all permutations from a given sequence.

Generated by Epydoc 2.1 on Sun May 15 17:34:14 2005 http://epydoc.sf.net