Георги обнови решението на 03.04.2015 12:46 (преди над 9 години)
+from math import sqrt
+
+
+def fibonacci():
+ current_member, next_member = 1, 1
+
+ while True:
+ yield current_member
+ current_member, next_member = next_member, current_member + next_member
+
+
+def primes():
+ def is_prime(number):
+ for i in range(2, int(sqrt(number)) + 1):
+ if number % i == 0:
+ return False
+
+ return True
+
+ current_number = 2
+
+ while True:
+ yield current_number
+ current_number += 1
+
+ while not is_prime(current_number):
+ current_number += 1
+
+
+def alphabet(code='', letters=''):
+ if letters == '':
+ alphabets = {
+ 'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя',
+ 'lat': 'abcdefghijklmnopqrstuvwxyz'
+ }
+
+ letters = alphabets[code]
+
+ for letter in letters:
+ yield letter
+
+
+def intertwined_sequences(descriptors, generator_definitions={}):
+ sequence_generators = {
+ 'fibonacci': fibonacci,
+ 'primes': primes,
+ 'alphabet': alphabet
+ }
+
+ sequence_generators.update(generator_definitions)
+
+ generators = {}
+ for sequence in descriptors:
+ name = sequence.pop('sequence')
+ length = sequence.pop('length')
+
+ if name not in generators:
+ generators[name] = iter(sequence_generators[name](**sequence))
+
+ while length > 0:
+ yield next(generators[name])
+ length -= 1