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

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

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

Резултати

  • 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

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

EEEE..EEEEEE..
======================================================================
ERROR: test_bg_alphabet (test.TestAlphabet)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_endless_letters_generator (test.TestAlphabet)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_glagolitic (test.TestAlphabet)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_lat_alphabet (test.TestAlphabet)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_generator_definitions (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_infinite_intertwined (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_intertwine (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_intertwine_repeating_builtin (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_kwargs_generator (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_repeating_with_different_args (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

----------------------------------------------------------------------
Ran 14 tests in 20.263s

FAILED (errors=10)

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

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

+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