Женя обнови решението на 03.04.2015 13:16 (преди над 9 години)
+def fibonacci():
+ first = 1
+ second = 1
+ while True:
+ yield first
+ first, second = second, first + second
+
+
+import math
+
+def primes():
+ count_prime = 2
+ while True:
+ IsItPrime = True
+ root = int(math.sqrt(count_prime))
+ for x in range(2, root + 1):
+ if count_prime % x == 0:
+ IsItPrime = False
+ if IsItPrime:
+ yield count_prime
+ count_prime = count_prime + 1
+
+
+def alphabet(code= "", letters = ""):
+ while letters is "":
+ if code == "lat":
+ codes = chr(97)
+ while True:
+ if chr(97)<=codes<=chr(122):
+ yield codes
+ codes = chr(ord(codes) + 1)
+
+ if code == "bg":
+ codes = chr(1072)
+ while True:
+ if chr(1072)<=codes<=chr(1103):
+ yield codes
+ codes = chr(ord(codes) + 1)
+
+ index = 0
+ while True:
+ yield letters[index]
+ index = index + 1
+
+
+def intertwined_sequences(*args):
+ result = []
+ fibonacci_numbers = fibonacci()
+ prime = primes()
+ bg = alphabet(code='bg')
+ lat = alphabet(code='lat')
+
+ for params in args:
+ for param in params:
+
+ if param.get('sequence') == 'fibonacci':
+ for j in range(0,param.get('length')):
+ result.append(next(fibonacci_numbers))
+
+ if param.get('sequence') == 'primes':
+ for j in range(0,param.get('length')):
+ result.append(next(prime))
+
+ if param.get('sequence') == 'alphabet':
+ if param.get('code') == 'bg':
+
+ for j in range(0,param.get('length')):
+ result.append(next(bg))
+ if param.get('code') == 'lat':
+
+ for j in range(0,param.get('length')):
+ result.append(next(lat))
+ if param.get('letters'):
+ for j in range(0,param.get('length')):
+ result.append(param.get('letters')[j])
+
+ return result