Python  1.0
Functions
_11_ncsub Namespace Reference

Non-continuous subsequences. More...

Functions

def C (n, k)
 Calculates the k-combination of an integer. More...
 
def nsubs (n)
 The number of k-combinations. More...
 
def ncsub (seq)
 Enumerates all non-continuous subsequences for a given sequence. More...
 
def main (argv=None)
 

Detailed Description

Non-continuous subsequences.

Author
Paulo Roma
Since
10/07/2010
See also
http://www.rosettacode.org/wiki/Non_Continuous_Subsequences
http://www.research.att.com/~njas/sequences/A002662

Function Documentation

◆ C()

def _11_ncsub.C (   n,
  k 
)

Calculates the k-combination of an integer.

Parameters
na given integer.
kan integer lesser than n.
Returns
\(\frac{n!}{k!(n-k)!} = {n \choose k}\)

Referenced by nsubs().

◆ main()

def _11_ncsub.main (   argv = None)

References _01d_dec2bin.input, and ncsub().

◆ ncsub()

def _11_ncsub.ncsub (   seq)

Enumerates all non-continuous subsequences for a given sequence.

A subsequence contains some subset of the elements of this sequence, in the same order. A continuous subsequence is one in which no elements are missing between the first and last elements of the subsequence.

The idea behind this is to loop over the possible lengths of subsequence, finding all subsequences, then discarding those which are continuous.

Non Recursive version.

Parameters
seqa list of integers.
Returns

References nsubs().

Referenced by main().

◆ nsubs()

def _11_ncsub.nsubs (   n)

The number of k-combinations.

References C().

Referenced by ncsub().