Виктория обнови решението на 03.04.2015 01:37 (преди над 9 години)
+def fibonacci():
+ current = 1
+ next = 1
+ while True:
+ yield current
+ temporary = current
+ current = next
+ next += temporary
+
+
+def is_prime(candidate, is_divider):
+ if is_divider == 1:
+ return True
+ elif candidate % is_divider == 0:
+ return False
+ else:
+ return is_prime(candidate, is_divider - 1)
+
+
+def primes():
+ number = 2
+ while True:
+ yield number
+ number = number + 1
+ while is_prime(number, floor(sqrt(number))) is False:
+ number = number + 1
+
+
+def alphabet(letters=0, code=0):
+ if code == 'lat' and letters is 0:
+ latin_letter_code = 97
+ while latin_letter_code < 123:
+ yield chr(latin_letter_code)
+ latin_letter_code += 1
+ elif code == 'bg' and letters is 0:
+ bulgarian_letter_code = 1072
+ while bulgarian_letter_code < 1104:
+ if bulgarian_letter_code == 1099 or bulgarian_letter_code == 1101:
+ bulgarian_letter_code += 1
+ yield chr(bulgarian_letter_code)
+ bulgarian_letter_code += 1
+ else:
+ next_letter = 0
+ while next_letter < len(letters):
+ yield letters[next_letter]
+ next_letter += 1
+
+
+def intertwined_sequences(argument, generator_definitions=0):
+ generator_definitions.update({'fibonacci': fibonacci, 'primes': primes})
+ generators = {}
+ for key, value in generator_definitions.items():
+ generators[key] = value()
+ flag = False
+
+ for arg in argument:
+ while arg['length'] > 0:
+ arg['length'] -= 1
+ if arg['sequence'] == 'alphabet':
+ if 'code' in arg.keys() and flag is False:
+ flag = True
+ it = alphabet(code=arg['code'])
+ elif 'letters' in arg.keys() and flag is False:
+ it = alphabet(letters=arg['letters'])
+ flag = True
+ yield next(it)
+ else:
+ yield next(generators[arg['sequence']])