updated from Atlas repo

This commit is contained in:
Luciano Ramalho
2014-12-14 01:26:42 -02:00
parent dcd59eef31
commit 33d65dc590
21 changed files with 359 additions and 299 deletions

View File

@@ -1,27 +1,11 @@
"""
Arithmetic progression class
>>> ap = ArithmeticProgression(1, .5, 3)
>>> list(ap)
[1.0, 1.5, 2.0, 2.5]
# BEGIN ARITPROG_ITERTOOLS
import itertools
"""
import array
from collections import abc
class ArithmeticProgression:
def __init__(self, begin, step, end=None):
self.begin = float(begin)
self.step = float(step)
self.end = end # None -> "infinite" series
def __iter__(self):
result = self.begin
forever = self.end is None
while forever or result < self.end:
yield result
result += self.step
raise StopIteration
def aritprog_gen(begin, step, end=None):
first = type(begin + step)(begin)
ap_gen = itertools.count(first, step)
if end is not None:
ap_gen = itertools.takewhile(lambda n: n < end, ap_gen)
return ap_gen
# END ARITPROG_ITERTOOLS