Минх обнови решението на 02.04.2015 23:03 (преди над 9 години)
+lat = "abcdefghijklmnopqrstuvwxyz"
+bg = "абвгдежзийклмнопрстуфхцчшщъьюя"
+
+
+def fibonacci():
+ previous_number = 0
+ number = 1
+ yield 1
+ while True:
+ yield number + previous_number
+ number += previous_number
+ previous_number = number - previous_number
+
+
+def prime():
+ number = 2
+ while True:
+ if __is_prime(number):
+ yield number
+ number += 1
+
+
+def alphabet(*, code=None, letters=None):
+ lang = None
+ if code == 'lat':
+ lang = lat
+ elif code == 'bg':
+ lang = bg
+ else:
+ lang = letters
+
+ letter_index = 0
+ while letter_index < len(lang):
+ yield lang[letter_index]
+ letter_index += 1
+
+
+def __is_prime(number):
+ if number < 2:
+ return False
+ if number == 2:
+ return True
+ if number % 2 == 0:
+ return False
+ for current_number in range(3, number):
+ if number % current_number == 0:
+ return False
+ return True
+
+
+def intertwined_sequences(specifications, generator_definitions=None):
+ generators = {
+ 'alphabet': alphabet,
+ 'primes': prime,
+ 'fibonacci': fibonacci
+ }
+ generator_instances = dict()
+ generator_arguments = dict()
+
+ if generator_definitions is not None:
+ for key, value in generator_definitions.items():
+ generators[key] = value
+
+ for spec in specifications:
+ sequence = spec['sequence']
+ if sequence not in generator_instances:
+ if generator_definitions is not None and sequence in generator_definitions and len(spec) > 2:
+ if sequence not in generator_arguments:
+ argument = spec.copy()
+ del argument['sequence']
+ del argument['length']
+ generator_arguments[sequence] = argument
+ generator_instances[sequence] = iter(generators[sequence](**generator_arguments[sequence]))
+ elif sequence != 'alphabet':
+ generator_instances[sequence] = iter(generators[sequence]())
+ else:
+ if 'alphabet' not in generator_arguments:
+ if 'letters' in spec:
+ generator_arguments['alphabet'] = spec['letters']
+ generator_instances['alphabet'] = iter(generators['alphabet'](letters=spec['letters']))
+ elif 'bg' in spec.values():
+ generator_arguments['alphabet'] = bg
+ generator_instances['alphabet'] = iter(generators['alphabet'](letters=bg))
+ else:
+ generator_arguments['alphabet'] = lat
+ generator_instances['alphabet'] = iter(generators['alphabet'](letters=lat))
+
+ if sequence is not 'alphabet':
+ if len(spec) > 2:
+ while spec['length']:
+ spec['length'] -= 1
+ generator_instances_obj = generator_instances[sequence]
+ yield next(generator_instances_obj)
+ else:
+ while spec['length']:
+ spec['length'] -= 1
+ generator_instances_obj = generator_instances[sequence]
+ yield next(generator_instances_obj)
+ else:
+ while spec['length']:
+ spec['length'] -= 1
+ generator_instances_obj = generator_instances['alphabet']
+ yield next(generator_instances_obj)
Опитах да съкращавам имената колкото мога, но все пак има някои редове по 109 символа. Дано това да не се отразява много на оценяването