Решение на Генератори и итератори от Венцислав Димитров

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

Към профила на Венцислав Димитров

Резултати

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

Код

import math
ALPHABETS = {
'lat': 'abcdefghijklmnopqrstuvwxyz',
'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя'
}
def fibonacci():
lastNum = 0
newNum = 1
while 1:
lastNum, newNum = newNum, lastNum + newNum
yield lastNum
def primes():
counter = 2
while 1:
isprime = True
for iteration in range(2, int(math.sqrt(counter) + 1)):
if counter % iteration == 0:
isprime = False
break
if isprime:
yield counter
counter += 1
def alphabet(**kwargs):
counter = 0
elements = ''
if 'letters' in kwargs.keys():
elements = kwargs['letters']
if 'code' in kwargs.keys():
elements = ALPHABETS[kwargs['code']]
while 1:
yield elements[counter]
counter += 1

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

.E....EEEEEE..
======================================================================
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_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 14.201s

FAILED (errors=7)

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

Венцислав обнови решението на 02.04.2015 02:05 (преди около 9 години)

+import math
+
+
+ALPHABETS = {
+ 'lat': 'abcdefghijklmnopqrstuvwxyz',
+ 'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя'
+}
+
+
+def fibonacci():
+ lastNum = 0
+ newNum = 1
+ while 1:
+ lastNum, newNum = newNum, lastNum + newNum
+ yield lastNum
+
+
+def primes():
+ counter = 2
+ while 1:
+ isprime = True
+ for iteration in range(2, int(math.sqrt(counter) + 1)):
+ if counter % iteration == 0:
+ isprime = False
+ break
+ if isprime:
+ yield counter
+ counter += 1
+
+
+def alphabet(**kwargs):
+ counter = 0
+ elements = ''
+ if 'letters' in kwargs.keys():
+ elements = kwargs['letters']
+
+ if 'code' in kwargs.keys():
+ elements = ALPHABETS[kwargs['code']]
+
+ while 1:
+ yield elements[counter]
+ counter += 1