Мария обнови решението на 03.04.2015 15:02 (преди над 9 години)
+import math
+
+def fibonacci():
+ value_one , value_two = 1, 1
+ while True:
+ yield value_one
+ value_one, value_two = value_two, value_one + value_two
+
+
+
+def primes():
+ counter = 2
+ while True:
+ isPrime = True
+ for x in range(2, int(math.sqrt(counter) + 1)):
+ if counter % x == 0:
+ isPrime = False
+ break
+ if isPrime:
+ yield counter
+ counter += 1
+
+
+
+def alphabet(code = "", letters = ""):
+ if letters is not "":
+ i = 0
+ one = 1
+ while one == 1:
+ yield letters[i]
+ i = i + 1
+ else:
+ if code == 'lat':
+ for a in range(97, 122):
+ yield chr(a)
+ a = a + 1
+ if code == 'bg':
+ for b in range(1072, 1103):
+ yield chr(b)
+ b = b + 1
+
+
+
+def intertwined_sequences(*args):
+ result = []
+ fibonacci_numbers = fibonacci()
+ prime = primes()
+ bulgarian_cyrillic = alphabet(code='bg')
+ latin = alphabet(code='lat')
+
+ for parameters in args:
+ for parameter in parameters:
+ if parameter.get('sequence') == 'fibonacci':
+ for i in range(0,parameter.get('length')):
+ result.append(next(fibonacci_numbers))
+ if parameter.get('sequence') == 'primes':
+ for i in range(0,parameter.get('length')):
+ result.append(next(prime))
+ if parameter.get('sequence') == 'alphabet':
+ if parameter.get('code') == 'bg':
+ for i in range(0,parameter.get('length')):
+ result.append(next(bulgarian_cyrillic))
+ elif parameter.get('code') == 'lat':
+ for i in range(0,parameter.get('length')):
+ result.append(next(latin))
+ if parameter.get('letters'):
+ for i in range(0,parameter.get('length')):
+ result.append(parameter.get('letters')[i])
+ return result