Десислава обнови решението на 03.04.2015 16:10 (преди над 9 години)
+import math
+
+
+def fibonacci():
+ fib_number_1, fib_number_2 = 1, 1
+ yield fib_number_1
+ yield fib_number_2
+ while True:
+ fib_number_1, fib_number_2 = fib_number_2, fib_number_1 + fib_number_2
+ yield fib_number_2
+
+
+def is_prime(n):
+ if n == 1:
+ return False
+ for delim in range(2, n):
+ if n % delim == 0:
+ return False
+ return True
+
+
+def primes():
+ number = 2
+ while True:
+ if is_prime(number):
+ yield number
+ number += 1
+
+
+def alphabet(**kwargs):
+ if 'letters' in kwargs:
+ for letter in kwargs['letters']:
+ yield letter
+ elif kwargs['code'] == "lat":
+ alphabet = 'abcdefghijklmnopqrstuvwxyz'
+ for letter in alphabet:
+ yield letter
+ else:
+ alphabet = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ for letter in alphabet:
+ yield letter
+
+
+def intertwined_sequences(sequences, **kwargs):
+ generators = {}
+ for sequence_info in sequences:
+ if sequence_info['sequence'] not in generators:
+ if sequence_info['sequence'] == 'fibonacci':
+ generators['fibonacci'] = iter(fibonacci())
+ elif sequence_info['sequence'] == 'primes':
+ generators['primes'] = iter(primes())
+ elif sequence_info['sequence'] == 'alphabet':
+ if 'letters' in sequence_info:
+ generators['alphabet'] = iter(
+ alphabet(letters=sequence_info['letters']))
+ else:
+ generators['alphabet'] = iter(
+ alphabet(code=sequence_info['code']))
+ else:
+ arguments = {
+ name: sequence_info[name] for name in sequence_info
+ if name != 'sequence' and name != 'length'}
+ generators[sequence_info['sequence']] = iter(
+ kwargs['generator_definitions'][sequence_info['sequence']]
+ (**arguments))
+
+ for iteration in range(sequence_info['length']):
+ yield next(generators[sequence_info['sequence']])