Елица обнови решението на 02.04.2015 00:58 (преди над 9 години)
+from math import sqrt
+import itertools
+
+
+def fibonacci():
+ x = 1
+ y = 0
+ while True:
+ yield x + y
+ y = y + x
+ x = y - x
+
+
+def primes():
+ return (x for x in itertools.count(2, 1) if is_prime(x))
+
+
+def is_prime(n):
+ if n == 1:
+ return False
+ return len(list(filter(
+ lambda x: abs(n) % x == 0, range(2, int(sqrt(abs(n))) + 1)))) == 0
+
+
+def alphabet(code=0, letters=0):
+ lat_alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
+ 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
+ 'y', 'z']
+ bg_alphabet = ['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з', 'и', 'й', 'к', 'л',
+ 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
+ 'ш', 'щ', 'ъ', 'ь', 'ю', 'я']
+ if hasattr(letters, '__iter__'):
+ for x in letters:
+ yield x
+ elif code == 'lat':
+ for x in lat_alphabet:
+ yield x
+ else:
+ for x in bg_alphabet:
+ yield x
+
+
+def create_functions(row_description, generator_definitions):
+ all_functions = dict()
+ for function in row_description:
+ if function['sequence'] not in all_functions:
+ arguments = dict()
+ if function['sequence'] == 'fibonacci':
+ all_functions['fibonacci'] = fibonacci()
+ elif function['sequence'] == 'primes':
+ all_functions['primes'] = primes()
+ else:
+ for attribute in function:
+ if attribute != 'sequence' and attribute != 'length':
+ arguments[attribute] = function[attribute]
+ if function['sequence'] == 'alphabet':
+ all_functions[function['sequence']] = alphabet(**arguments)
+ else:
+ all_functions[function[
+ 'sequence']] = generator_definitions[
+ function['sequence']](**arguments)
+ return all_functions
+
+
+def intertwined_sequences(row_description, generator_definitions=0):
+ all_functions = create_functions(row_description, generator_definitions)
+ for function in row_description:
+ for number in range(0, function['length']):
+ yield next(all_functions[function['sequence']])