Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio n. 5
0
 def accumulate(self, op=operator.add, init=[]):
     return Sequence(chain(init, itertools2.accumulate(self, op, False)))
Esempio n. 6
0
 def accumulate(self,op,skip_first=False):
     return Sequence(itertools2.accumulate(self,op,skip_first))
Esempio n. 7
0
 def accumulate(self,op=operator.add,skip_first=False):
     return Sequence(itertools2.accumulate(self,op,skip_first))