Решение на Генератори и итератори от Явор Големанов

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

Към профила на Явор Големанов

Резултати

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

Код

import math
def fibonacci():
fib_number = 0
prev_fib = 1
while 1:
fib_number, prev_fib = prev_fib, fib_number + prev_fib
yield fib_number
def primes():
number = 2
while True:
is_prime = True
for possible_divisor in range(2, int(math.sqrt(number) + 1)):
if number % possible_divisor == 0:
is_prime = False
break
if is_prime:
yield number
number += 1

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

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.178s

FAILED (errors=10)

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

Явор обнови решението на 03.04.2015 05:37 (преди над 9 години)

+import math
+
+
+def fibonacci():
+ x = 0
+ y = 1
+ while 1:
+ x, y = y, x + y
+ yield x
+
+
+def primes():
+ count = 2
+
+ while True:
+ isprime = True
+
+ for x in range(2, int(math.sqrt(count) + 1)):
+ if count % x == 0:
+ isprime = False
+ break
+
+ if isprime:
+ yield count
+
+ count += 1

Явор обнови решението на 03.04.2015 05:44 (преди над 9 години)

import math
def fibonacci():
- x = 0
- y = 1
+ fib_number = 0
+ prev_fib = 1
while 1:
- x, y = y, x + y
- yield x
+ fib_number, prev_fib = prev_fib, fib_number + prev_fib
+ yield fib_number
def primes():
- count = 2
+ number = 2
while True:
- isprime = True
+ is_prime = True
- for x in range(2, int(math.sqrt(count) + 1)):
- if count % x == 0:
- isprime = False
+ for possible_divisor in range(2, int(math.sqrt(number) + 1)):
+ if number % possible_divisor == 0:
+ is_prime = False
break
- if isprime:
- yield count
+ if is_prime:
+ yield number
- count += 1
+ number += 1