Виктор обнови решението на 03.04.2015 16:59 (преди над 9 години)
+def fibonacci():
+ a, b = 1, 1
+ while 1:
+ yield a
+ a, b = b, a+b
+
+
+from math import sqrt
+
+
+def primes():
+ def is_simple(s):
+ for i in range(2,int(sqrt(s)) + 1):
+ if s % i == 0:
+ return False
+ return True
+ n = 2
+ while 1:
+ if is_simple(n):
+ yield n
+ n += 1
+
+
+def alphabet(**kwargs):
+ bg = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ lat = 'abcdefghijklmnopqrstuvwxyz'
+ if 'letters' in kwargs:
+ for i in kwargs['letters']:
+ yield i
+ elif kwargs['code'] == 'bg':
+ for i in bg:
+ yield i
+ elif kwargs['code'] == 'lat':
+ for i in lat:
+ yield i
+
+
+def intertwined_sequences(s, generator_definitions={}):
+ fib = fibonacci()
+ pri = primes()
+ for i in s:
+ if i['sequence'] == 'alphabet':
+ if 'letters' in i:
+ alph = alphabet(letters=i['letters'])
+ if 'code' in i:
+ alph = alphabet(code=i['code'])
+ break
+ for i in s:
+ for k in range(i['length']):
+ if i['sequence'] == 'fibonacci':
+ for l in range(i['length']):
+ yield next(fib)
+ if i['sequence'] == 'primes':
+ for l in range(i['length']):
+ yield next(pri)
+ if i['sequence'] == 'alphabet':
+ for l in range(i['length']):
+ yield next(alph)
+ if generator_definitions:
+ for key, value in generator_definitions.items():
+ if i['sequence'] == key:
+ sequence = value()
+ for l in range(i['length']):
+ yield next(sequence)