コード例 #1
0
def test():
    assert general_product((1, 2, 3)) == 6
    assert general_product((1, 2, 3, 4)) == 24
    assert general_product(
        ((0, 1), 2, 3)) == (0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1)
    assert general_product(
        (2, 3), start=(0, 1)) == (0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1)
コード例 #2
0
def test():
    assert general_product((1, 2, 3)) == 6
    assert general_product((1, 2, 3, 4)) == 24
    assert general_product(((0, 1), 2, 3)) == (0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
                                               1)
    assert general_product((2, 3), start=(0, 1)) == (0, 1, 0, 1, 0, 1, 0, 1, 0,
                                                     1, 0, 1)
    
コード例 #3
0
ファイル: perm.py プロジェクト: cool-RR/python_toolbox
 def __pow__(self, exponent):
     '''Raise the perm by the power of `exponent`.'''
     assert isinstance(exponent, numbers.Integral)
     if exponent <= -1:
         return self.inverse ** (- exponent)
     elif exponent == 0:
         return self.nominal_perm_space[0]
     else:
         assert exponent >= 1
         return misc_tools.general_product((self,) * exponent)
コード例 #4
0
 def __pow__(self, exponent):
     '''Raise the perm by the power of `exponent`.'''
     assert isinstance(exponent, numbers.Integral)
     if exponent <= -1:
         return self.inverse**(-exponent)
     elif exponent == 0:
         return self.nominal_perm_space[0]
     else:
         assert exponent >= 1
         return misc_tools.general_product((self, ) * exponent)
コード例 #5
0
ファイル: factorials.py プロジェクト: cool-RR/python_toolbox
def factorial(x, start=1):
    '''
    Calculate a factorial.
    
    This differs from the built-in `math.factorial` in that it allows a `start`
    argument. If one is given, the function returns `(x!)/(start!)`.
    
    Examples:
    
        >>> factorial(5)
        120
        >>> factorial(5, 3)
        60

    '''
    from python_toolbox import misc_tools
    return misc_tools.general_product(range(start, x+1), start=1)
コード例 #6
0
ファイル: factorials.py プロジェクト: drawcode/python_toolbox
def factorial(x, start=1):
    '''
    Calculate a factorial.
    
    This differs from the built-in `math.factorial` in that it allows a `start`
    argument. If one is given, the function returns `(x!)/(start!)`.
    
    Examples:
    
        >>> factorial(5)
        120
        >>> factorial(5, 3)
        60

    '''
    from python_toolbox import misc_tools
    return misc_tools.general_product(range(start, x+1), start=1)
コード例 #7
0
ファイル: misc.py プロジェクト: drawcode/python_toolbox
def product(numbers):
    '''Get the product of all the numbers in `numbers`.'''
    from python_toolbox import misc_tools
    return misc_tools.general_product(numbers, start=1)
コード例 #8
0
ファイル: misc.py プロジェクト: drawcode/python_toolbox
def product(numbers):
    '''Get the product of all the numbers in `numbers`.'''
    from python_toolbox import misc_tools
    return misc_tools.general_product(numbers, start=1)