Васил обнови решението на 31.03.2015 23:04 (преди над 9 години)
+def fibonacci():
+
+ first, second = 1, 1
+ while True:
+ yield first
+ first, second = second, first + second
+
+
+import math
+
+
+def primes():
+
+ number = 2
+ while True:
+ prime = True
+ for r in range(2, int(math.sqrt(number) + 1)):
+ if number % r == 0:
+ prime = False
+ break
+ if prime:
+ yield number
+ number += 1
+
+
+def alphabet(code='', letters=''):
+
+ if code == 'lat':
+ letters = 'abcdefghijklmnopqrstuvwxyz'
+ elif code == 'bg':
+ letters = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+
+ for l in letters:
+ yield l
+
+
+def intertwined_sequences(iterative):
+
+ fib = fibonacci()
+ pri = primes()
+ alp_lat = alphabet(code='lat')
+ alp_bg = alphabet(code='bg')
+
+ for func in iterative:
+ if func['sequence'] == 'fibonacci':
+ for i in range(func['length']):
+ yield next(fib)
+ elif func['sequence'] == 'primes':
+ for j in range(func['length']):
+ yield next(pri)
+ elif func['sequence'] == 'alphabet':
+ if func['code'] == 'lat':
+ for l in range(func['length']):
+ yield next(alp_lat)
+ elif func['code'] == 'bg':
+ for l in range(func['length']):
+ yield next(alp_bg)