Атанас обнови решението на 03.04.2015 10:49 (преди над 9 години)
+def fibonacci():
+ value1, value2 = 1, 1
+ while True:
+ yield value1
+ value2 += value1
+ value1 = value2 - value1
+
+
+def is_prime(value):
+ sum = 0
+ for d in range(1, value+1):
+ if value % d == 0:
+ sum += d
+ return sum == value+1
+
+
+def primes():
+ value = 2
+ while True:
+ if is_prime(value):
+ yield value
+ value += 1
+
+
+BG_ALPHABET = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ENG_ALPHABET = 'abcdefghijklmnopqrstuvwxyz'
+
+
+def alphabet(code='', letters=''):
+ value = 0
+ if letters:
+ while True:
+ yield letters[value]
+ value += 1
+ else:
+ if code == 'bg':
+ while True:
+ yield BG_ALPHABET[value]
+ value += 1
+ else:
+ while True:
+ yield ENG_ALPHABET[value]
+ value += 1
+
+
+BASIC_GENERATOR_DEFINITIONS = {
+ 'fibonacci': fibonacci,
+ 'primes': primes,
+ 'alphabet': alphabet
+}
+
+
+def ones():
+ while True:
+ yield 1
+
+
+def naturals():
+ number = 1
+ while True:
+ yield number
+ number += 1
+
+
+def multiples_of(num):
+ i = 1
+ while True:
+ yield num * i
+ i += 1
+
+
+def intertwined_sequences(iterable_object, generator_definitions={}):
+ generator_definitions.update(BASIC_GENERATOR_DEFINITIONS)
+ used_generators = {}
+ for element in iterable_object:
+ arguments = {key: value for key, value in element.items()
+ if key != 'sequence' and key != 'length'}
+ if element['sequence'] not in used_generators:
+ generator = iter(generator_definitions[element['sequence']](**arguments))
+ used_generators.update({element['sequence']: generator})
+ print(type(used_generators[element['sequence']]))
+ value = 0
+ while value < element['length']:
+ yield next(used_generators[element['sequence']])
+ value += 1