Решение на Генератори и итератори от Симеон Кръстев

Обратно към всички решения

Към профила на Симеон Кръстев

Резултати

  • 3 точки от тестове
  • 0 бонус точки
  • 3 точки общо
  • 4 успешни тест(а)
  • 10 неуспешни тест(а)

Код

import math
def fibonacci():
prev = 0
curr = 1
while True:
yield curr
temp = curr + prev
prev = curr
curr = temp
def primes():
number = 2
while True:
if (isPrime(number)):
yield number
number += 1
def isPrime(number):
if number < 2:
return False
for i in range(2, math.floor(math.sqrt(number))+1):
if number % i == 0:
return False
return True

Лог от изпълнението

▸ Покажи лога

История (1 версия и 0 коментара)

Симеон обнови решението на 03.04.2015 00:05 (преди около 10 години)

▸ Покажи разликите
+import math
+
+
+def fibonacci():
+ prev = 0
+ curr = 1
+ while True:
+ yield curr
+ temp = curr + prev
+ prev = curr
+ curr = temp
+
+
+def primes():
+ number = 2
+ while True:
+ if (isPrime(number)):
+ yield number
+ number += 1
+
+
+def isPrime(number):
+ if number < 2:
+ return False
+ for i in range(2, math.floor(math.sqrt(number))+1):
+ if number % i == 0:
+ return False
+ return True