Решение на Генератори и итератори от Калоян Евтимов

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

Към профила на Калоян Евтимов

Резултати

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

Код

CONVERT_TO_ALPHABET = {'lat': "abcdefghijklmnopqrstuvwxyz",
'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя'}
def fibonacci(*opt):
older = 0
old = 1
curr = 1
if opt:
p = 1
while p <= opt[0]:
yield curr
curr = old + older
older = old
old = curr
p += 1
raise StopIteration
else:
while True:
yield curr
curr = old + older
older = old
old = curr
def is_prime(number):
for i in range(2, number // 2 + 1):
if number % i == 0:
return False
return True
def primes(*opt):
curr = 2
if opt:
p = 1
while p <= opt[0]:
yield curr
curr += 1
while not is_prime(curr):
curr += 1
p += 1
raise StopIteration
else:
while True:
yield curr
curr += 1
while not is_prime(curr):
curr += 1
def alphabet(code='', letters=''):
if letters != '':
curr_letters = letters
else:
curr_letters = CONVERT_TO_ALPHABET[code]
return(let for let in curr_letters)

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

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

FAILED (errors=6)

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

Калоян обнови решението на 03.04.2015 13:07 (преди над 9 години)

+CONVERT_TO_ALPHABET = {'lat': "abcdefghijklmnopqrstuvwxyz",
+ 'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя'}
+
+
+def fibonacci(*opt):
+ older = 0
+ old = 1
+ curr = 1
+ if opt:
+ p = 1
+ while p <= opt[0]:
+ yield curr
+ curr = old + older
+ older = old
+ old = curr
+ p += 1
+ else:
+ while True:
+ yield curr
+ curr = old + older
+ older = old
+ old = curr
+
+
+def is_prime(number):
+ for i in range(2, number // 2 + 1):
+ if number % i == 0:
+ return False
+ return True
+
+
+def primes(*opt):
+ curr = 2
+ if opt:
+ p = 1
+ while p <= opt[0]:
+ yield curr
+ curr += 1
+ while not is_prime(curr):
+ curr += 1
+ p += 1
+ else:
+ while True:
+ yield curr
+ curr += 1
+ while not is_prime(curr):
+ curr += 1
+
+
+def alphabet(code='', letters=''):
+ if letters != '':
+ curr_letters = letters
+ else:
+ curr_letters = CONVERT_TO_ALPHABET[code]
+ return(let for let in curr_letters)

Калоян обнови решението на 03.04.2015 16:39 (преди над 9 години)

CONVERT_TO_ALPHABET = {'lat': "abcdefghijklmnopqrstuvwxyz",
'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя'}
def fibonacci(*opt):
older = 0
old = 1
curr = 1
if opt:
p = 1
while p <= opt[0]:
yield curr
curr = old + older
older = old
old = curr
p += 1
+ raise StopIteration
else:
while True:
yield curr
curr = old + older
older = old
old = curr
def is_prime(number):
for i in range(2, number // 2 + 1):
if number % i == 0:
return False
return True
def primes(*opt):
curr = 2
if opt:
p = 1
while p <= opt[0]:
yield curr
curr += 1
while not is_prime(curr):
curr += 1
p += 1
+ raise StopIteration
else:
while True:
yield curr
curr += 1
while not is_prime(curr):
curr += 1
def alphabet(code='', letters=''):
if letters != '':
curr_letters = letters
else:
curr_letters = CONVERT_TO_ALPHABET[code]
return(let for let in curr_letters)