Йордан обнови решението на 02.04.2015 23:55 (преди над 9 години)
+def fibonacci():
+ current, next = 1, 1
+ while 1:
+ yield current
+ current, next = next, current + next
+
+
+def isprime(number):
+ for devider in range(2, number):
+ if number % devider == 0:
+ return False
+ return True
+
+
+def primes():
+ number = 2
+ while 1:
+ if isprime(number):
+ yield number
+ number = number + 1
+
+
+def intertwined_sequences(items):
+ for generator in items:
+ if generator['sequence'] == 'fibonacci':
+ fibonacci_numbers = fibonacci()
+ for j in range(0, generator['length']):
+ yield next(fibonacci_numbers)
+ elif generator['sequence'] == 'primes':
+ prime_numbers = primes()
+ for j in range(0, generator['length']):
+ yield next(prime_numbers)
+ else:
+ if 'code' in generator:
+ alphabetical_order = alphabet(code=generator['code'])
+ else:
+ alphabetical_order = alphabet(letters=generator['letters'])
+ for j in range(0, generator['length']):
+ yield next(alphabetical_order)
+
+
+def alphabet(*, letters='', code=''):
+ bg = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ lat = 'abcdefghijklmnopqrstuwxyz'
+ alphabet = letters if letters else bg if code == 'bg' else lat
+ for letter in alphabet:
+ yield letter