예제 #1
0
파일: oeis.py 프로젝트: pombredanne/Goulib
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
예제 #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
예제 #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
예제 #4
0
파일: math2.py 프로젝트: Python3pkg/Goulib
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
예제 #5
0
파일: container.py 프로젝트: goulu/Goulib
 def accumulate(self, op=operator.add, init=[]):
     return Sequence(chain(init, itertools2.accumulate(self, op, False)))
예제 #6
0
파일: oeis.py 프로젝트: pombredanne/Goulib
 def accumulate(self,op,skip_first=False):
     return Sequence(itertools2.accumulate(self,op,skip_first))
예제 #7
0
 def accumulate(self,op=operator.add,skip_first=False):
     return Sequence(itertools2.accumulate(self,op,skip_first))