Спасимир обнови решението на 03.04.2015 15:59 (преди над 9 години)
+import itertools
+
+import math
+
+
+def fibonacci():
+ a = b = 1
+ while True:
+ yield a
+ a, b = b, a + b
+
+
+def primes():
+ return (i for i in itertools.count(2)
+ if all(i % t for t in range(2, int(math.sqrt(i)) + 1)))
+
+
+def alphabet(**kwargs):
+ latin = 'abcdefghijklmnopqrstuvwxyz'
+ bg = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ if 'letters' in kwargs:
+ for item in kwargs['letters']:
+ yield item
+ elif 'code' in kwargs:
+ if kwargs['code'] == 'lat':
+ for item in latin:
+ yield item
+ elif kwargs['code'] == 'bg':
+ for item in bg:
+ yield item
+
+
+def intertwined_sequences(composition, generator_definitions={}):
+ sequence1 = fibonacci()
+ sequence2 = primes()
+ for item in composition:
+ if item['sequence'] == 'alphabet':
+ if 'letters' in item:
+ sequence3 = alphabet(letters=item['letters'])
+ elif 'code' in item:
+ sequence3 = alphabet(code=item['code'])
+ break
+ for item in composition:
+ if item['sequence'] == 'fibonacci':
+ for i in range(item['length']):
+ yield next(sequence1)
+ elif item['sequence'] == 'primes':
+ for i in range(item['length']):
+ yield next(sequence2)
+ elif item['sequence'] == 'alphabet':
+ for i in range(item['length']):
+ yield next(sequence3)
+ elif generator_definitions:
+ for key, value in generator_definitions.items():
+ if item['sequence'] == key:
+ sequence4 = value()
+ for i in range(item['length']):
+ yield next(sequence4)
+