Решение на Генератори и итератори от Виктор Драганов

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

Към профила на Виктор Драганов

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 8 успешни тест(а)
  • 6 неуспешни тест(а)

Код

__author__ = 'Veke'
import math
import string
def fibonacci():
a, b = 1, 1
while 1:
yield a
temp = a
a = b
b += temp
def primes():
yield 2
prime = 3
is_prime = True
while 1:
for divisor in range(2, int(math.sqrt(prime) + 1)):
if prime % divisor == 0:
is_prime = False
break
if is_prime:
yield prime
is_prime = True
prime += 1
def alphabet(code=None, letters=None):
latin = string.ascii_lowercase
cyrillic = 'абвгдежзийклмнопрстуфхцчшщъьюя'
count = 0
if letters is None:
if code == 'lat':
iterator = iter(latin)
if code == 'bg':
iterator = iter(cyrillic)
else:
iterator = iter(letters)
while 1:
yield next(iterator)

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

......EEEEEE..
======================================================================
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 12.203s

FAILED (errors=6)

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

Виктор обнови решението на 03.04.2015 16:29 (преди около 9 години)

+__author__ = 'Veke'
+
+import math
+import string
+
+
+def fibonacci():
+ a, b = 1, 1
+ while 1:
+ yield a
+ temp = a
+ a = b
+ b = temp + b
+
+
+def primes():
+ yield 2
+ prime = 3
+ is_prime = True
+ while 1:
+ for divisor in range(2, int(math.sqrt(prime) + 1)):
+ if prime % divisor == 0:
+ is_prime = False
+ break
+ if is_prime:
+ yield prime
+ is_prime = True
+ prime += 1
+
+
+def alphabet(code=None, letters=None):
+ latin = string.ascii_lowercase
+ cyrillic = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
+ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
+ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?']
+ count = 0
+ if letters is None:
+ if code == 'lat':
+ iterator = iter(latin)
+ if code == 'bg':
+ iterator = iter(cyrillic)
+ else:
+ iterator = iter(letters)
+ while 1:
+ yield next(iterator)

Виктор обнови решението на 03.04.2015 16:44 (преди около 9 години)

__author__ = 'Veke'
-import math
-import string
+import math
+import string
def fibonacci():
a, b = 1, 1
while 1:
yield a
temp = a
a = b
- b = temp + b
+ b += temp
def primes():
yield 2
prime = 3
is_prime = True
while 1:
for divisor in range(2, int(math.sqrt(prime) + 1)):
if prime % divisor == 0:
is_prime = False
break
if is_prime:
yield prime
is_prime = True
prime += 1
def alphabet(code=None, letters=None):
latin = string.ascii_lowercase
- cyrillic = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
- '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
- '?', '?', '?', '?', '?', '?', '?', '?', '?', '?']
+ cyrillic = 'абвгдежзийклмнопрстуфхцчшщъьюя'
count = 0
if letters is None:
if code == 'lat':
iterator = iter(latin)
if code == 'bg':
iterator = iter(cyrillic)
else:
iterator = iter(letters)
while 1:
yield next(iterator)