Решение на Генератори и итератори от Радослав Аспарухов

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

Към профила на Радослав Аспарухов

Резултати

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

Код

import string
BG_ALPHABET = {"абвгдежзийклмнопрстуфхцчшщъьюя"}
def fibonacci():
a, b = 0, 1
while 1:
yield a
a, b = b, a + b
def primes():
n = 2
primes = set()
while True:
for p in primes:
if n % p == 0:
break
else:
primes.add(n)
yield n
n += 1
def alphabet(**kwargs):
if 'code' in kwargs:
if kwargs['code'] == 'lat':
for x in string.ascii_lowercase:
yield x
if kwargs['code'] == 'bg':
for x in BG_ALPHABET:
yield x
if 'letters' in kwargs:
for x in kwargs['letters']:
yield x

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

E...EEEEEEEE..
======================================================================
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_fibonacci (test.TestFibonacci)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_longer_sequence (test.TestFibonacci)
----------------------------------------------------------------------
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 18.403s

FAILED (errors=9)

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

Радослав обнови решението на 03.04.2015 10:01 (преди над 9 години)

+import string
+
+BG_ALPHABET = {"абвгдежзийклмнопрстуфхцчшщъьюя"}
+
+
+def fibonacci():
+ a, b = 0, 1
+ while 1:
+ yield a
+ a, b = b, a + b
+
+
+def primes():
+ n = 2
+ primes = set()
+ while True:
+ for p in primes:
+ if n % p == 0:
+ break
+ else:
+ primes.add(n)
+ yield n
+ n += 1
+
+
+def alphabet(**kwargs):
+ if 'code' in kwargs:
+ if kwargs['code'] == 'lat':
+ for x in string.ascii_lowercase:
+ yield x
+ if kwargs['code'] == 'bg':
+ for x in BG_ALPHABET:
+ yield x
+ if 'letters' in kwargs:
+ for x in kwargs['letters']:
+ yield x