Ejemplo n.º 1
0
def bell():
    """Bell or exponential numbers: number of ways to partition a set of n labeled elements.
    """

    blist, b = [1], 1
    yield 1
    yield 1
    while True:
        blist = list(itertools2.accumulate([b]+blist))
        b = blist[-1]
        yield b
Ejemplo n.º 2
0
def bell():
    """Bell or exponential numbers: number of ways to partition a set of n labeled elements.
    """

    blist, b = [1], 1
    yield 1
    yield 1
    while True:
        blist = list(itertools2.accumulate([b]+blist))
        b = blist[-1]
        yield b
Ejemplo n.º 3
0
def is_perfect(n):
    """
    :return: -1 if n is deficient, 0 if perfect, 1 if abundant
    :see: https://en.wikipedia.org/wiki/Perfect_number,
    https://en.wikipedia.org/wiki/Abundant_number,
    https://en.wikipedia.org/wiki/Deficient_number
    """
    # return sign(abundance(n)) #simple, but might be slow for large n
    for s in itertools2.accumulate(divisors(n)):
        if s>2*n:
            return 1
    return 0 if s==2*n else -1
Ejemplo n.º 4
0
def is_perfect(n):
    """
    :return: -1 if n is deficient, 0 if perfect, 1 if abundant
    :see: https://en.wikipedia.org/wiki/Perfect_number,
    https://en.wikipedia.org/wiki/Abundant_number,
    https://en.wikipedia.org/wiki/Deficient_number
    """
    # return sign(abundance(n)) #simple, but might be slow for large n
    for s in itertools2.accumulate(divisors(n)):
        if s > 2 * n:
            return 1
    return 0 if s == 2 * n else -1
Ejemplo n.º 5
0
 def accumulate(self, op=operator.add, init=[]):
     return Sequence(chain(init, itertools2.accumulate(self, op, False)))
Ejemplo n.º 6
0
 def accumulate(self,op,skip_first=False):
     return Sequence(itertools2.accumulate(self,op,skip_first))
Ejemplo n.º 7
0
 def accumulate(self,op=operator.add,skip_first=False):
     return Sequence(itertools2.accumulate(self,op,skip_first))