Решение на Генератори и итератори от Никола Шахпазов

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

Към профила на Никола Шахпазов

Резултати

  • 1 точка от тестове
  • 0 бонус точки
  • 1 точка общо
  • 2 успешни тест(а)
  • 12 неуспешни тест(а)

Код

#!/usr/bin/env python
# -*- coding: utf-8 -*-
def fibonacci_numbers():
a, b = 0,1
yield a
yield b
while True:
a, b = b, a + b
yield b
def prime_numbers():
""" Generate an infinite sequence of prime numbers.
"""
D = {}
q = 2
while True:
if q not in D:
yield q
D[q * q] = [q]
else:
for p in D[q]:
D.setdefault(p + q, []).append(p)
del D[q]
q += 1
def alphabet(code='en', letters=None):
alphs = {
'bg': 'абвгдежзийклмнопрстуфхцчщшщъюя',
'en': 'abcdefghijklmnopqrstuwxyz'
}
items = letters or alphs[code]
for i in items:
yield i
#def intertwined_sequences(generators):
# return reduce(lambda x, y: x + y, )

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

E..EEEEEEEEEEE
======================================================================
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_lat_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

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

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

----------------------------------------------------------------------
Ran 14 tests in 24.119s

FAILED (errors=12)

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

Никола обнови решението на 03.04.2015 15:39 (преди над 9 години)

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+def fibonacci_numbers():
+ a, b = 0,1
+ yield a
+ yield b
+ while True:
+ a, b = b, a + b
+ yield b
+
+def prime_numbers():
+ """ Generate an infinite sequence of prime numbers.
+ """
+ D = {}
+ q = 2
+
+ while True:
+ if q not in D:
+ yield q
+ D[q * q] = [q]
+ else:
+ for p in D[q]:
+ D.setdefault(p + q, []).append(p)
+ del D[q]
+ q += 1
+
+
+def alphabet(code='en', letters=None):
+ alphs = {
+ 'bg': 'абвгдежзийклмнопрстуфхцчщшщъюя',
+ 'en': 'abcdefghijklmnopqrstuwxyz'
+ }
+ items = letters or alphs[code]
+ for i in items:
+ yield i
+
+#def intertwined_sequences(generators):
+# return reduce(lambda x, y: x + y, )