Решение на Генератори и итератори от Женя Георгиева

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

Към профила на Женя Георгиева

Резултати

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

Код

def fibonacci():
first = 1
second = 1
while True:
yield first
first, second = second, first + second
import math
def primes():
count_prime = 2
while True:
IsItPrime = True
root = int(math.sqrt(count_prime))
for x in range(2, root + 1):
if count_prime % x == 0:
IsItPrime = False
if IsItPrime:
yield count_prime
count_prime = count_prime + 1
def alphabet(code= "", letters = ""):
while letters is "":
if code == "lat":
codes = chr(97)
while True:
if chr(97)<=codes<=chr(122):
yield codes
codes = chr(ord(codes) + 1)
if code == "bg":
codes = chr(1072)
while True:
if chr(1072)<=codes<=chr(1103):
yield codes
codes = chr(ord(codes) + 1)
index = 0
while True:
yield letters[index]
index = index + 1
def intertwined_sequences(*args):
result = []
fibonacci_numbers = fibonacci()
prime = primes()
bg = alphabet(code='bg')
lat = alphabet(code='lat')
for params in args:
for param in params:
if param.get('sequence') == 'fibonacci':
for j in range(0,param.get('length')):
result.append(next(fibonacci_numbers))
if param.get('sequence') == 'primes':
for j in range(0,param.get('length')):
result.append(next(prime))
if param.get('sequence') == 'alphabet':
if param.get('code') == 'bg':
for j in range(0,param.get('length')):
result.append(next(bg))
if param.get('code') == 'lat':
for j in range(0,param.get('length')):
result.append(next(lat))
if param.get('letters'):
for j in range(0,param.get('length')):
result.append(param.get('letters')[j])
return result

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

EE....EE..EE..
======================================================================
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_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_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.339s

FAILED (errors=6)

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

Женя обнови решението на 03.04.2015 13:16 (преди почти 9 години)

+def fibonacci():
+ first = 1
+ second = 1
+ while True:
+ yield first
+ first, second = second, first + second
+
+
+import math
+
+def primes():
+ count_prime = 2
+ while True:
+ IsItPrime = True
+ root = int(math.sqrt(count_prime))
+ for x in range(2, root + 1):
+ if count_prime % x == 0:
+ IsItPrime = False
+ if IsItPrime:
+ yield count_prime
+ count_prime = count_prime + 1
+
+
+def alphabet(code= "", letters = ""):
+ while letters is "":
+ if code == "lat":
+ codes = chr(97)
+ while True:
+ if chr(97)<=codes<=chr(122):
+ yield codes
+ codes = chr(ord(codes) + 1)
+
+ if code == "bg":
+ codes = chr(1072)
+ while True:
+ if chr(1072)<=codes<=chr(1103):
+ yield codes
+ codes = chr(ord(codes) + 1)
+
+ index = 0
+ while True:
+ yield letters[index]
+ index = index + 1
+
+
+def intertwined_sequences(*args):
+ result = []
+ fibonacci_numbers = fibonacci()
+ prime = primes()
+ bg = alphabet(code='bg')
+ lat = alphabet(code='lat')
+
+ for params in args:
+ for param in params:
+
+ if param.get('sequence') == 'fibonacci':
+ for j in range(0,param.get('length')):
+ result.append(next(fibonacci_numbers))
+
+ if param.get('sequence') == 'primes':
+ for j in range(0,param.get('length')):
+ result.append(next(prime))
+
+ if param.get('sequence') == 'alphabet':
+ if param.get('code') == 'bg':
+
+ for j in range(0,param.get('length')):
+ result.append(next(bg))
+ if param.get('code') == 'lat':
+
+ for j in range(0,param.get('length')):
+ result.append(next(lat))
+ if param.get('letters'):
+ for j in range(0,param.get('length')):
+ result.append(param.get('letters')[j])
+
+ return result

Женя обнови решението на 03.04.2015 15:03 (преди почти 9 години)

def fibonacci():
first = 1
second = 1
while True:
yield first
first, second = second, first + second
import math
def primes():
count_prime = 2
while True:
IsItPrime = True
root = int(math.sqrt(count_prime))
for x in range(2, root + 1):
if count_prime % x == 0:
IsItPrime = False
if IsItPrime:
yield count_prime
count_prime = count_prime + 1
def alphabet(code= "", letters = ""):
while letters is "":
if code == "lat":
codes = chr(97)
while True:
if chr(97)<=codes<=chr(122):
yield codes
codes = chr(ord(codes) + 1)
if code == "bg":
codes = chr(1072)
while True:
if chr(1072)<=codes<=chr(1103):
yield codes
codes = chr(ord(codes) + 1)
index = 0
while True:
yield letters[index]
index = index + 1
def intertwined_sequences(*args):
result = []
fibonacci_numbers = fibonacci()
prime = primes()
bg = alphabet(code='bg')
lat = alphabet(code='lat')
for params in args:
for param in params:
if param.get('sequence') == 'fibonacci':
for j in range(0,param.get('length')):
result.append(next(fibonacci_numbers))
if param.get('sequence') == 'primes':
for j in range(0,param.get('length')):
result.append(next(prime))
if param.get('sequence') == 'alphabet':
- if param.get('code') == 'bg':
+ if param.get('code') == 'bg':
for j in range(0,param.get('length')):
result.append(next(bg))
- if param.get('code') == 'lat':
+ if param.get('code') == 'lat':
for j in range(0,param.get('length')):
result.append(next(lat))
+
if param.get('letters'):
for j in range(0,param.get('length')):
result.append(param.get('letters')[j])
return result