Цветан обнови решението на 03.04.2015 09:01 (преди над 9 години)
+import math
+
+BG_ALPHABET = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+LAT_ALPHABET = 'abcdefghijklmnopqrstuvwxyz'
+LATIN_ALPHABET_CODE = 'lat'
+
+
+def fibonacci():
+ a, b = 1, 1
+ while True:
+ yield a
+ a, b = b, a + b
+
+
+def is_prime(number):
+ if number > 1:
+ if number == 2:
+ return True
+ if number % 2 == 0:
+ return False
+ for current in range(3, int(math.sqrt(number) + 1), 2):
+ if number % current == 0:
+ return False
+ return True
+ return False
+
+
+def primes():
+ number = 2
+ while True:
+ if is_prime(number):
+ yield number
+ number += 1
+
+
+def get_aphabet_by_code(code):
+ if code == LATIN_ALPHABET_CODE:
+ return LAT_ALPHABET
+
+ return BG_ALPHABET
+
+
+def alphabet(code='', letters=''):
+ if not letters:
+ letters = get_aphabet_by_code(code)
+
+ for letter in letters:
+ yield letter
+
+
+GENERATORS = {
+ 'fibonacci': fibonacci,
+ 'primes': primes,
+ 'alphabet': alphabet
+}
+
+
+def generator_factory(generator):
+ sequence = generator['sequence']
+
+ generator_copy = generator.copy()
+
+ generator_copy.pop('sequence')
+ generator_copy.pop('length')
+
+ return GENERATORS[sequence](**generator_copy)
+
+
+def intertwined_sequences(generators, generator_definitions={}):
+ current_generators = {}
+ GENERATORS.update(generator_definitions)
+ for generator in generators:
+ sequence = generator['sequence']
+ if sequence not in current_generators:
+ current_generators[sequence] = generator_factory(generator)
+
+ for x in range(generator['length']):
+ yield next(current_generators[sequence])
+
+ return current_generators