Кристиян обнови решението на 03.04.2015 14:23 (преди над 9 години)
+def fibonacci():
+ current_num = 1
+ next_num = 1
+ while True:
+ yield current_num
+ current_num, next_num = next_num, current_num + next_num
+
+def primes():
+ saved_primes = {}
+ prime_number = 2
+ while True:
+ if prime_number not in saved_primes:
+ yield prime_number
+ saved_primes[prime_number * prime_number] = [prime_number]
+ else:
+ for saved_prime_number in saved_primes[prime_number]:
+ saved_primes.setdefault(saved_prime_number + prime_number, []).append(saved_prime_number)
+ del saved_primes[prime_number]
+ prime_number += 1
+
+def alphabet(code='', letters=''):
+ if letters is '':
+ if code is 'lat':
+ selected_alphabet = 'abcdefghijklmnopqrstuvwxyz'
+ elif code is 'bg':
+ selected_alphabet = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ else:
+ selected_alphabet = letters
+ for position in range(len(selected_alphabet)):
+ yield selected_alphabet[position]
+
+def intertwined_sequences(sequences, generator_definitions=''):
+ seq_inst = {}
+ for sequence in sequences:
+ seq_arg = dict(sequence)
+ seq_arg.pop('sequence')
+ seq_arg.pop('length')
+ if sequence['sequence'] not in seq_inst:
+ if sequence['sequence'] in globals():
+ seq_inst[sequence['sequence']] = iter(globals()[sequence['sequence']](**seq_arg))
+ else:
+ seq_inst[sequence['sequence']] = iter(generator_definitions[sequence['sequence']](**seq_arg))
+ for x in range(sequence['length']):
+ yield(next(seq_inst[sequence['sequence']]))