Георги обнови решението на 02.04.2015 19:48 (преди над 9 години)
+def fibonacci():
+ current, next = 1, 1
+ while True:
+ yield current
+ current, next = next, next + current
+
+
+def primes():
+ deviders = {}
+ x = 2
+ while True:
+ if x not in deviders:
+ yield x
+ deviders[x*x] = [x]
+ else:
+ for d in deviders[x]:
+ deviders.setdefault(d + x, []).append(d)
+ del deviders[x]
+ x += 1
+
+
+def alphabet(**kwargs):
+ if 'letters' in kwargs:
+ letters = kwargs['letters']
+ elif 'code' in kwargs:
+ if kwargs['code'] is 'bg':
+ letters = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ elif kwargs['code'] is 'lat':
+ letters = 'abcdefghijklmnopqrstuvwxyz'
+ for letter in letters:
+ yield letter
+
+
+def intertwined_sequences(sequences, generator_definitions=None):
+ generators = {}
+ for s in sequences:
+ sequence = s.pop('sequence')
+ length = s.pop('length')
+ if sequence not in generators.keys():
+ if sequence in globals():
+ generators[sequence] = globals()[sequence](**s)
+ else:
+ generators[sequence] = generator_definitions[sequence](**s)
+ for _ in range(length):
+ yield next(generators[sequence])