На баба туршията

Краен срок
26.03.2015 17:00

Срокът за предаване на решения е отминал

Баба прави туршия. От оная де и викат "царска". В една от 18-те "оригинални" рецепти участват следните съставки:

  • камби
  • карфиол
  • моркови
  • целина

Баба има 4 купчинки от горните съставки и неизвестен брой буркани. Бурканите са бездънни и безкрайни, поемат всичко що баба реши да натика в тях.

Баба обаче иска да пръсне съставките по специален начин и за това прави следното:

  • взима 1 камбa (ако е възможно)
  • 2 карфиола (ако / колкото е възможно)
  • 4 моркова (ако / колкото е възможно)
  • 3 целини (ако / колкото е възможно)

и цикли така последователно през бурканите. В случай, че някоя от съставките свърши - продължава по познатата схема с останалите продукти и така докато продуктите свършат си цикли през бездънните буркани.

Напишете функция:

def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
    ....

На която се подават само стойности от тип int отговарящи съответно на броя буркани / камби / карфиол / моркови и целина и връща списък от итератори, които отговарят на съответното съдържание в бурканите.

Итераторите трябва да връщат стринговете 'bell_pepper', 'cauliflower', 'carrot', 'celery' за съответните неща, които "вадим" от буркана с next. Подредбата вътре в тях няма значение, важно е броя да е коректен.

Пример:

jars = jars_content(jars=3, bell_peppers=1, cauliflowers=3, carrots=5, celeries=2)

type(jars)  # => <class 'list'>
jars[0]  #=> <generator object ....>
first_jar = list(jars[0])
second_jar = list(jars[1])
third_jar = list(jars[2])
first_jar.count('bell_pepper')  # 1
first_jar.count('cauliflower')  # 2
first_jar.count('celery')  # 2
second_jar.count('cauliflower')  # 1
second_jar.count('celery')  # 0
len(third_jar)  # 0

Третия буркан по схемата на баба остава празен, дано се усети и не го свари.

Решения

Павел Димитров
  • Некоректно
  • 2 успешни тест(а)
  • 3 неуспешни тест(а)
Павел Димитров
PEPERS_PER_JAR = 1
CAULIFLOWERS_PER_JAR = 2
CARROTS_PER_JAR = 4
CELERIES_PER_JAR = 3
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
packed_jars = list()
for jar in range(jars):
current_jar = []
if bell_peppers >= PEPERS_PER_JAR:
current_jar.append(PEPERS_PER_JAR)
bell_peppers -= PEPERS_PER_JAR
else:
current_jar.append(bell_peppers)
bell_peppers = 0
if cauliflowers >= CAULIFLOWERS_PER_JAR:
current_jar.append(CAULIFLOWERS_PER_JAR)
cauliflowers -= CAULIFLOWERS_PER_JAR
else:
current_jar.append(cauliflowers)
cauliflowers = 0
if carrots >= CARROTS_PER_JAR:
current_jar.append(CARROTS_PER_JAR)
carrots -= CARROTS_PER_JAR
else:
current_jar.append(carrots)
carrots = 0
if celeries >= CELERIES_PER_JAR:
current_jar.append(CELERIES_PER_JAR)
celeries -= CELERIES_PER_JAR
else:
current_jar.append(celeries)
celeries = 0
current_jar = JarIterator(*current_jar)
packed_jars.append(current_jar)
return packed_jars
def JarIterator(bell_peppers, cauliflowers, carrots, celeries):
for i in range(bell_peppers):
yield "bell_peppers"
for i in range(cauliflowers):
yield "cauliflowers"
for i in range(carrots):
yield "carrots"
for i in range(celeries):
yield "celeries"
..FFF
======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-115b8as/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 0 != 3

======================================================================
FAIL: test_sample_test_with_easy_to_follow_products_distribution (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-115b8as/test.py", line 40, in test_sample_test_with_easy_to_follow_products_distribution
    self.assertEqual(jar_content.count('bell_pepper'), 1)
AssertionError: 0 != 1

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-115b8as/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 0 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=3)
Станислав Гатев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Станислав Гатев
from itertools import chain
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
def package(name, total_size, share_size, jar):
shares_count = total_size // share_size
share = ((shares_count + jars - jar - 1) // jars) * share_size
if shares_count % jars == jar:
share += total_size % share_size
return (name for _ in range(share))
return [chain(package('bell_pepper', bell_peppers, 1, jar),
package('cauliflower', cauliflowers, 2, jar),
package('carrot', carrots, 4, jar),
package('celery', celeries, 3, jar))
for jar in range(jars)]
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Мартин Стоев
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Мартин Стоев
class Ingredients:
ingredient_names = ['bell_pepper', 'cauliflower',
'carrot', 'celery']
def __init__(self, bell_peppers, cauliflowers, carrots, celeries):
self.ingredient = [bell_peppers, cauliflowers, carrots, celeries]
def generate_jars(times_in_jar, ingredients):
for index in range(len(times_in_jar)):
count = 0
while count < times_in_jar[index]:
if ingredients.ingredient[index] == 0:
break
ingredients.ingredient[index] -= 1
count += 1
yield ingredients.ingredient_names[index]
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
times_in_jar = [1, 2, 4, 3]
ingredients = Ingredients(
bell_peppers, cauliflowers, carrots, celeries)
return [generate_jars(times_in_jar, ingredients)
for count in range(jars)]
..F.F
======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-godjmp/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 2 != 3

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-godjmp/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=2)
Илиян Якимов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Илиян Якимов
from itertools import repeat
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
if jars == 0:
return []
iterators = []
i = jars
store = []
while jars:
jar = []
if bell_peppers >= 1:
jar.append('bell_pepper')
bell_peppers -= 1
if cauliflowers >= 2:
jar.extend(repeat('cauliflower', 2))
cauliflowers -= 2
elif cauliflowers >= 1:
jar.extend(repeat('cauliflower', cauliflowers))
cauliflowers -= cauliflowers
if carrots >= 4:
jar.extend(repeat('carrot', 4))
carrots -= 4
elif carrots >= 1:
jar.extend(repeat('carrot', carrots))
carrots -= carrots
if celeries >= 3:
jar.extend(repeat('celery', 3))
celeries -= 3
elif celeries >= 1:
jar.extend(repeat('celery', celeries))
celeries -= celeries
store.append(jar)
jars -= 1
j = 0
while bell_peppers or cauliflowers or carrots or celeries:
if j == i:
j = 0
if bell_peppers >= 1:
store[j].append('bell_pepper')
bell_peppers -= 1
if cauliflowers >= 2:
store[j].extend(repeat('cauliflower', 2))
cauliflowers -= 2
elif cauliflowers >= 1:
store[j].extend(repeat('cauliflower', cauliflowers))
cauliflowers -= cauliflowers
if carrots >= 4:
store[j].extend(repeat('carrot', 4))
carrots -= 4
elif carrots >= 1:
store[j].extend(repeat('carrot', carrots))
carrots -= carrots
if celeries >= 3:
store[j].extend(repeat('celery', 3))
celeries -= 3
elif celeries >= 1:
store[j].extend(repeat('celery', celeries))
celeries -= celeries
j += 1
for jar in store:
iterators.append(iter(jar))
return iterators
.....
----------------------------------------------------------------------
Ran 5 tests in 0.026s

OK
Светлин Василев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Светлин Василев
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
mylist = [list() for i in range(jars)]
while (bell_peppers > 0 or cauliflowers > 0 or
carrots > 0 or celeries > 0):
for i in mylist:
bell_peppers_counter = 0
cauliflowers_counter = 0
carrots_counter = 0
celeries_counter = 0
while bell_peppers > 0 and bell_peppers_counter < 1:
i.append('bell_pepper')
bell_peppers -= 1
bell_peppers_counter += 1
while cauliflowers > 0 and cauliflowers_counter < 2:
i.append('cauliflower')
cauliflowers -= 1
cauliflowers_counter += 1
while carrots > 0 and carrots_counter < 4:
i.append('carrot')
carrots -= 1
carrots_counter += 1
while celeries > 0 and celeries_counter < 3:
i.append('celery')
celeries -= 1
celeries_counter += 1
myiterlist = [list()] * jars
return [iter(i) for i in mylist]
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Елена Денева
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Елена Денева
MAX_INGREDIENTS = range(1, 5)
INGREDIENTS = ['bell_pepper', 'cauliflower', 'celery', 'carrot']
def jar(content):
for ingredient, count in content:
for i in range(0, count):
yield ingredient
class Factory:
def __init__(self, jars, bell_peppers, cauliflowers, carrots, celeries):
self.jars = jars
self.content = [bell_peppers, cauliflowers, celeries, carrots]
def __iter__(self):
return self
def __next__(self):
if self.jars <= 0:
raise StopIteration
self.jars -= 1
content = list(map(min, zip(self.content, MAX_INGREDIENTS)))
self.content = [self.content[i] - content[i] for i in range(0, 4)]
return jar(zip(INGREDIENTS, content))
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
return list(Factory(jars, bell_peppers, cauliflowers, carrots, celeries))
..F.F
======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1un90ja/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 2 != 3

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1un90ja/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.009s

FAILED (failures=2)
Йоан Динков
  • Некоректно
  • 2 успешни тест(а)
  • 3 неуспешни тест(а)
Йоан Динков
from itertools import repeat
from itertools import chain
from itertools import islice
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
bell_peppers_list = repeat('bell_pepper', bell_peppers)
cauliflowers_list = repeat('cauliflower', cauliflowers)
carrots_list = repeat('carrot', carrots)
celeries_list = repeat('celery', celeries)
def items():
for jar in range(0, jars):
yield chain(islice(bell_peppers_list, 1),
islice(cauliflowers_list, 2),
islice(carrots_list, 3),
islice(celeries_list, 4))
return list(items())
..FFF
======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1q0579l/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 2 != 3

======================================================================
FAIL: test_sample_test_with_easy_to_follow_products_distribution (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1q0579l/test.py", line 41, in test_sample_test_with_easy_to_follow_products_distribution
    self.assertEqual(jar_content.count('carrot'), 4)
AssertionError: 3 != 4

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1q0579l/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=3)
Валентин Латунов
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Валентин Латунов
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
recepie = {
'bell_pepper': 1, 'cauliflower': 2, 'carrot': 4, 'celery': 3
}
avaliable = {
'bell_pepper': bell_peppers, 'cauliflower': cauliflowers,
'carrot': carrots, 'celery': celeries
}
def fill_the_good_stuff():
for veggie, amount in recepie.items():
for _ in range(amount):
if avaliable[veggie]:
avaliable[veggie] -= 1
yield veggie
return [fill_the_good_stuff() for _ in range(jars)]
..F.F
======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-11yxfpx/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 2 != 3

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-11yxfpx/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=2)
Цветелина Александрова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Цветелина Александрова
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
items = []
all_jars_turshia = JarContent(bell_peppers, cauliflowers,
carrots, celeries)
for i in range(0, jars):
items.append([])
while all_jars_turshia.get_total_number_of_items() > 0:
for i in range(0, jars):
items[i].extend(
all_jars_turshia.get_items_for_current_jar())
turshia_iterators = []
for i in range(0, jars):
turshia_iterators.append(JarIterator(items[i]))
return turshia_iterators
class JarIterator:
def __init__(self, turshia):
self.turshia = turshia
self.index = 0
def __iter__(self):
return self
def __next__(self):
try:
item = self.turshia[self.index]
except IndexError:
raise StopIteration
self.index += 1
return item
class JarContent:
def __init__(self, bell_peppers, cauliflowers,
carrots, celeries):
self.bell_peppers = bell_peppers
self.cauliflowers = cauliflowers
self.carrots = carrots
self.celeries = celeries
def get_items_for_current_jar(self):
item_names = ['bell_pepper', 'cauliflower', 'carrot', 'celery']
item_counts = [1, 2, 4, 3]
available_amounts = [self.bell_peppers, self.cauliflowers,
self.carrots, self.celeries]
items_for_jar = []
print(available_amounts)
for i in range(0, len(item_names)):
attr_name = item_names[i] + "s"
if i == len(item_names) - 1:
attr_name = "celeries"
if available_amounts[i] > item_counts[i]:
items_for_jar.extend([item_names[i]] * item_counts[i])
setattr(self, attr_name,
available_amounts[i] - item_counts[i])
else:
items_for_jar.extend([item_names[i]] *
available_amounts[i])
setattr(self, attr_name, 0)
return items_for_jar
def get_total_number_of_items(self):
total_number = self.bell_peppers + self.cauliflowers
total_number += self.carrots + self.celeries
return total_number
.....
----------------------------------------------------------------------
Ran 5 tests in 0.007s

OK
Гален Георгиев
  • Некоректно
  • 2 успешни тест(а)
  • 3 неуспешни тест(а)
Гален Георгиев
def generate(bell_peppers, cauliflowers, carrots, celeries):
for i in range(bell_peppers):
yield "bell_pepper"
for i in range(cauliflowers):
yield "cauliflower"
for i in range(carrots):
yield "carrot"
for i in range(celeries):
yield "celery"
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
jar = 0
jar_lists = []
while jar <= jars:
jar_lists.append(generate(min(1, bell_peppers), min(2, cauliflowers),
min(4, carrots), min(3, celeries)))
bell_peppers = max(0, bell_peppers - 1)
cauliflowers = max(0, cauliflowers - 2)
carrots = max(0, carrots - 4)
celeries = max(0, celeries - 3)
jar += 1
return jar_lists
..FFF
======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1wjb16t/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 2 != 3

======================================================================
FAIL: test_sample_test_with_easy_to_follow_products_distribution (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1wjb16t/test.py", line 40, in test_sample_test_with_easy_to_follow_products_distribution
    self.assertEqual(jar_content.count('bell_pepper'), 1)
AssertionError: 0 != 1

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1wjb16t/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=3)
Виктор Цонев
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Виктор Цонев
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
baba_jars = []
for i in range(jars):
baba_jars.append(jar(bell_peppers, cauliflowers, carrots, celeries))
bell_peppers -= 1
cauliflowers -= 2
carrots -= 4
celeries -= 3
return baba_jars
def jar(bell_peppers, cauliflowers, carrots, celeries):
if bell_peppers > 0:
yield 'bell_pepper'
if cauliflowers >= 2:
for i in range(2):
yield 'cauliflower'
else:
for i in range(cauliflowers):
yield 'cauliflower'
if carrots >= 4:
for i in range(4):
yield 'carrot'
else:
for i in range(carrots):
yield 'carrot'
if celeries >= 3:
for i in range(3):
yield 'celery'
else:
for i in range(celeries):
yield 'celery'
..F.F
======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-15bm8a3/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 2 != 3

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-15bm8a3/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=2)
Теодор Климентов
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Теодор Климентов
def stuff_jar(quantities, jar, jars):
vegetables = ['bell_pepper', 'cauliflower', 'carrot', 'celery']
portions = [1, 2, 4, 3]
for v in range(4):
amount = ((quantities[v] // portions[v]) // jars) * portions[v]
amount += max(0, (quantities[v] - amount * jars) - jar * portions[v])
for _ in range(amount):
yield vegetables[v]
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
quantities = [bell_peppers, cauliflowers, carrots, celeries]
return [stuff_jar(quantities, jar, jars) for jar in range(jars)]
....F
======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-4a0c31/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 3 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=1)
Георги Чулев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Чулев
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
amounts = [bell_peppers, cauliflowers, celeries, carrots]
veggies = ('bell_pepper', 'cauliflower', 'celery', 'carrot')
crate = [[] for jar in range(jars)]
while amounts != [0, 0, 0, 0] and jars > 0:
for jar in range(len(crate)):
for veggie, amount in enumerate(amounts):
if amount >= (veggie + 1):
crate[jar].extend([veggies[veggie]] * (veggie + 1))
amounts[veggie] -= (veggie + 1)
else:
crate[jar].extend([veggies[veggie]] * amount)
amounts[veggie] = 0
return [iter(jar) for jar in crate]
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Христо Тодоров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Тодоров
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
jar = [[] for x in range(jars)]
all_products = {'bell_pepper': bell_peppers, 'cauliflower': cauliflowers,
'carrot': carrots, 'celery': celeries}
need_products = {'bell_pepper': 1, 'cauliflower': 2,
'carrot': 4, 'celery': 3}
while any(list(all_products.values())):
for i in range(0, jars):
temp_jar = list()
for product in all_products.keys():
if (all_products[product] - need_products[product]) >= 0:
temp_jar += need_products[product] * [product]
all_products[product] -= need_products[product]
else:
temp_jar += all_products[product] * [product]
all_products[product] = 0
jar[i].extend(temp_jar)
return list(iter(map(lambda x: iter(x), jar)))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Спасимир Нонев
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Спасимир Нонев
import itertools
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
grandma_jars = []
for jar in range(jars):
grandma_jars.append(itertools.chain(
('bell_pepper' for pepper in range(min(bell_peppers, 1))),
('cauliflower' for cauliflower in range(min(cauliflowers, 2))),
('carrot' for carrot in range(min(carrots, 4))),
('celery' for celery in range(min(celeries, 3)))))
bell_peppers -= 1
cauliflowers -= 2
carrots -= 4
celeries -= 3
return grandma_jars
..F.F
======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-18gr0et/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 2 != 3

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-18gr0et/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=2)
Христиан Димитров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Христиан Димитров
from itertools import chain
def put_content_in_jars(vegies, index, num, vegie_name):
if vegies[index] - num >= 0:
vegies[index] = vegies[index] - num
else:
num = vegies[index]
vegies[index] = 0
return (vegie_name for i in range(num))
def are_vegies_in_jars(vegies):
return not all([vegies[i] == 0 for i in range(len(vegies))])
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
vegies = [bell_peppers, cauliflowers, carrots, celeries]
vegies_in_jar = []
while are_vegies_in_jars(vegies):
for jar in range(jars):
bell_peppers_in_jar = put_content_in_jars(vegies, 0, 1,
"bell_pepper")
cauliflowers_in_jar = put_content_in_jars(vegies, 1, 2,
"cauliflower")
carrots_in_jar = put_content_in_jars(vegies, 2, 4, "carrot")
celeries_in_jar = put_content_in_jars(vegies, 3, 3, "celery")
all = chain(bell_peppers_in_jar, cauliflowers_in_jar,
carrots_in_jar, celeries_in_jar)
if len(vegies_in_jar) != jar:
vegies_in_jar[jar] = chain(all, vegies_in_jar[jar])
else:
vegies_in_jar.append(all)
return vegies_in_jar
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Елица Христова
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Елица Христова
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
jarrs = list()
for current_jar in range(0, jars):
jarrs.append(products_in_jar(bell_peppers - current_jar,
cauliflowers -
(current_jar * 2), carrots -
(current_jar * 4),
celeries - (current_jar * 3), jars))
return jarrs
def products_in_jar(bell_peppers, cauliflowers, carrots, celeries, jars):
while bell_peppers > 0:
yield ('bell_pepper')
bell_peppers -= jars
while cauliflowers > 1:
yield ('cauliflower')
yield ('cauliflower')
cauliflowers -= 2 * jars
if cauliflowers == 1:
yield ('cauliflower')
while carrots > 3:
for x in range(0, 4):
yield ('carrot')
carrots -= 4 * jars
if carrots > 0:
for x in range(0, carrots):
yield ('carrot')
while celeries > 2:
for x in range(0, 3):
yield ('celery')
celeries -= 3 * jars
if celeries > 0:
for x in range(0, celeries):
yield ('celery')
raise StopIteration
....F
======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1vjf1g7/test.py", line 75, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('carrot'), 9)
AssertionError: 4 != 9

----------------------------------------------------------------------
Ran 5 tests in 0.006s

FAILED (failures=1)
Калоян Витанов
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Калоян Витанов
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
jar = []
while (
(bell_peppers != 0) or (cauliflowers != 0) or (carrots != 0)
or (celeries != 0)
):
for i in range(jars):
jar.append([])
for j in range(1):
if bell_peppers > 0:
jar[i].append('bell_pepper')
bell_peppers = bell_peppers - 1
for j in range(2):
if cauliflowers > 0:
jar[i].append('cauliflower')
cauliflowers = cauliflowers - 1
for j in range(4):
if carrots > 0:
jar[i].append('carrot')
carrots = carrots - 1
for j in range(3):
if celeries > 0:
jar[i].append('celery')
celeries = celeries - 1
q = []
for i in range(jars):
q.append(iter(jar[i]))
return q
.E...
======================================================================
ERROR: test_no_product_no_jars_content (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-19xh4nu/test.py", line 27, in test_no_product_no_jars_content
    cauliflowers=0
  File "/tmp/d20150331-20360-19xh4nu/solution.py", line 29, in jars_content
    q.append(iter(jar[i]))
IndexError: list index out of range

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (errors=1)
Спас Методиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Спас Методиев
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
remaining_products = [bell_peppers, cauliflowers, celeries, carrots]
jars_ = [[] for i in range(jars)]
i = 0
while any(remaining_products):
put_in_jar(jars_[i % jars], remaining_products)
i += 1
return [iter(x) for x in jars_]
def put_in_jar(jar, remaining_products):
products = ['bell_pepper', 'cauliflower', 'celery', 'carrot']
for i in range(4):
for x in range(i + 1):
if remaining_products[i] > 0:
jar.append(products[i])
remaining_products[i] -= 1
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Марина Узунова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Марина Узунова
def put_in_jar(content, jars, step, vegetable, count):
jars_count = jars
while count > 0:
i = 0
jars_count = jars
while jars_count > 0:
if(count) > 0:
if(count < step):
content[i].extend([vegetable]*count)
else:
content[i].extend([vegetable]*step)
count = count - step
jars_count = jars_count - 1
i = i + 1
else:
break
return content
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
ingredients = [
('bell_pepper', bell_peppers),
('cauliflower', cauliflowers),
('celery', celeries),
('carrot', carrots)
]
content = []
for i in list(range(jars)):
content.append([])
i = 0
for ingredient in ingredients:
i = i + 1
content = put_in_jar(content, jars, i, ingredient[0], ingredient[1])
print(content)
result = []
for jar in content:
result.append(iter(jar))
return result
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Любомир Гавадинов
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Любомир Гавадинов
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
result = []
recipe = {
'bell_pepper': 1,
'cauliflower': 2,
'celery': 3,
'carrot': 4
}
available = {
'bell_pepper': bell_peppers,
'cauliflower': cauliflowers,
'celery': celeries,
'carrot': carrots
}
for i in range(jars):
jar = []
for key, value in available.items():
needed = recipe[key]
if value >= needed:
add = needed
else:
add = value
available[key] -= add
jar.extend([key] * add)
result.append(jar)
for key, value in available.items():
c = 0
while value > 0:
c = 0 if c == jars else c
result[c].append(key)
c += 1
value -= 1
return list(map(iter, result))
....F
======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-149f6q8/test.py", line 74, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('cauliflower'), 12)
AssertionError: 11 != 12

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=1)
Aнтония Чекръкчиева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Aнтония Чекръкчиева
MAX_BELL_PEPPERS = 1
MAX_CAULIFLOWERS = 2
MAX_CARROTS = 4
MAX_CELERIES = 3
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
number_of_jars = []
for jar in range(jars):
number_of_jars.append(jar_ingredients(jars, bell_peppers,
cauliflowers, carrots, celeries, jar))
return number_of_jars
def jar_ingredients(jars, bell_peppers, cauliflowers, carrots, celeries, current_jar):
for i in range(number_of_extra_ingredients(MAX_BELL_PEPPERS,
bell_peppers, jars, current_jar)):
yield 'bell_pepper'
for i in range(number_of_extra_ingredients(MAX_CAULIFLOWERS,
cauliflowers, jars, current_jar)):
yield 'cauliflower'
for i in range(number_of_extra_ingredients(MAX_CARROTS,
carrots, jars, current_jar)):
yield 'carrot'
for i in range(number_of_extra_ingredients(MAX_CELERIES,
celeries, jars, current_jar)):
yield 'celery'
def number_of_extra_ingredients(max_el, number, jars, jar):
jars_el = []
extra = number - max_el * jars
for i in range(jars):
if number > max_el:
jars_el.append(max_el)
else:
jars_el.append(number)
number -= max_el
while extra > 0:
for el in range(len(jars_el)):
if extra >= max_el:
jars_el[el] += max_el
extra -= max_el
else:
jars_el[el] += extra
extra = 0
break
return jars_el[jar]
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Красимир Николов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Красимир Николов
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
jars_content_products = []
products = correct_products_jar(jars, bell_peppers, cauliflowers,
carrots, celeries)
for product in products:
jars_content_products.append(create_generator(product))
return jars_content_products
def correct_products_jar(jars, *args):
num_products = [1, 2, 4, 3]
products_in_jar = []
for product_counter, product in enumerate(args):
old_jar = False
temp_products_in_jar = []
whole_part = product // num_products[product_counter]
mod = product % num_products[product_counter]
if jars <= whole_part:
temp_jars = []
for num in range(whole_part):
repeat = num_products[product_counter]
if num % jars == 0 and num != 0 or old_jar:
old_jar = True
temp_jars[num % jars] += repeat
else:
temp_jars.append(repeat)
if num + 1 == whole_part:
temp_jars[(num + 1) % jars] += mod
temp_products_in_jar += temp_jars
else:
for num in range(jars):
if num < whole_part:
temp_products_in_jar.append(num_products[product_counter])
elif num == whole_part:
temp_products_in_jar.append(mod)
else:
temp_products_in_jar.append(0)
products_in_jar.append(temp_products_in_jar)
return zip_product_one_jar(products_in_jar)
def zip_product_one_jar(products_in_jars):
merge_products = []
for products in zip(*products_in_jars):
merge_products.append(products)
return merge_products
def create_generator(reps):
products_name = ['bell_pepper', 'cauliflower', 'carrot', 'celery']
for counter, rep in enumerate(reps):
for num in range(rep):
yield products_name[counter]
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Христо Хърсев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Хърсев
import itertools
from functools import reduce
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
bell_pepper = ('bell_pepper' for i in range(bell_peppers))
cauliflower = ('cauliflower' for i in range(cauliflowers))
carrot = ('carrot' for i in range(carrots))
celery = ('celery' for i in range(celeries))
jars_content = [[] for i in range(jars)]
jars_content_cycle = itertools.cycle(jars_content)
portions = itertools.zip_longest(
bell_pepper,
cauliflower,
cauliflower,
carrot,
carrot,
carrot,
carrot,
celery,
celery,
celery
)
for portion in portions:
next(jars_content_cycle).append(portion)
return [jar_ingredients(jar_content) for jar_content in jars_content]
def jar_ingredients(jar_content):
return (
ingredient
for ingredient in reduce(lambda x, y: x + y, jar_content, (None, ))
if ingredient is not None
)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Цветан Иванов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Иванов
INGREDIENT_PROPORTIONS = [1, 2, 4, 3]
INGREDIENT_NAMES = ["bell_pepper", "cauliflower", "carrot", "celery"]
def get_ingredient_if_any(ingredient, ingredient_position):
if ingredient > INGREDIENT_PROPORTIONS[ingredient_position]:
return INGREDIENT_PROPORTIONS[ingredient_position]
return ingredient
def ingredients_given(start, end, ingredient_position):
return (end - start) * INGREDIENT_PROPORTIONS[ingredient_position]
def generator(jars, ingredients, jar):
for index, ingredient in enumerate(ingredients):
while ingredient > 0:
ingredient -= ingredients_given(0, jar, index)
proportion = get_ingredient_if_any(ingredient, index)
for x in range(proportion):
yield INGREDIENT_NAMES[index]
ingredient -= proportion
ingredient -= ingredients_given(jar + 1, jars, index)
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
ingredients = [bell_peppers, cauliflowers, carrots, celeries]
return [generator(jars, ingredients, jar) for jar in range(jars)]
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Георги Димов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Димов
from itertools import repeat
def partitioning(product_amount, partition):
while(product_amount > 0):
if product_amount - partition >= 0:
yield partition
else:
yield product_amount
product_amount -= partition
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
products = {
'bell_pepper': (bell_peppers, 1),
'cauliflower': (cauliflowers, 2),
'carrot': (carrots, 4),
'celery': (celeries, 3)
}
jars_list = [[] for i in range(jars)]
for product, (amount, portion) in products.items():
generator = partitioning(amount, portion)
for index, portion_amount in enumerate(generator):
jars_list[index % jars].extend(repeat(product, portion_amount))
return list(map(iter, jars_list))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Иван Георгиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Георгиев
from itertools import cycle
def store(jar, resources):
ingredients = [(1, 'bell_pepper'), (2, 'cauliflower'),
(4, 'carrot'), (3, 'celery')]
for i in range(4):
if resources[i] - ingredients[i][0] <= 0:
items = [ingredients[i][1]] * resources[i]
jar += items
resources[i] = 0
else:
items = [ingredients[i][1]] * ingredients[i][0]
jar += items
resources[i] -= ingredients[i][0]
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
list_jars = [[] for i in range(jars)]
resources = [bell_peppers, cauliflowers, carrots, celeries]
iterator = cycle(list_jars)
while any(resources):
store(next(iterator), resources)
return [iter(jar) for jar in list_jars]
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Стилиян Стоянов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Стилиян Стоянов
PEPPER = 'bell_pepper'
CAULIFLOWER = 'cauliflower'
CARROT = 'carrot'
CELERY = 'celery'
CELERIES = 'celeries'
PRODUCTS = [PEPPER + 's', CAULIFLOWER + 's', CARROT + 's', CELERIES]
PRODUCT = [PEPPER, CAULIFLOWER, CARROT, CELERY]
NEEDS = [1, 2, 4, 3]
def jars_content(**kwargs):
ingredients = [kwargs[product] for product in PRODUCTS]
jars_with_carska = [None] * kwargs['jars']
each_jar_gets = calculate_each(ingredients, kwargs['jars'])
for i in range(kwargs['jars']):
jars_with_carska[i] = jar_generator(each_jar_gets[i])
return jars_with_carska
def jar_generator(jar_contains):
for i in range(4):
for j in range(jar_contains[i]):
yield PRODUCT[i]
def calculate_each(left_ingredients, jars_count):
each_jar_gets = [[0, 0, 0, 0] for jar in range(jars_count)]
INGREDIENTS_COUNT = 4
while(any(left_ingredients)):
for i in range(jars_count):
for j in range(INGREDIENTS_COUNT):
if left_ingredients[j] >= NEEDS[j]:
put_in_jar = NEEDS[j]
else:
put_in_jar = left_ingredients[j]
left_ingredients[j] -= put_in_jar
each_jar_gets[i][j] += put_in_jar
return each_jar_gets
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Деница Петрова
  • Некоректно
  • 1 успешни тест(а)
  • 4 неуспешни тест(а)
Деница Петрова
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
a = [bell_peppers*['bell_pepper']] + (jars-bell_peppers)*[[]]
b = [(cauliflowers//2)*2*['cauliflower']] + [(cauliflowers % 2)*['cauliflower']] + \
(jars - (cauliflowers//2) - cauliflowers % 2)*[[]]
c = [(carrots//4)*4*['carrot']] + [(carrots % 4)*['carrot']] + \
(jars - (carrots//4) - carrots % 4)*[[]]
d = [(celeries//3)*3*['celery']] + [(celeries % 3)*['celery']] + \
(jars - (celeries//3) - celeries % 3)*[[]]
a.sort(), b.sort(), c.sort(), d.sort()
content = [[a[i]+b[i]+c[i]+d[i]] for i in range(jars)]
return [(i for i in x) for y in content[::-1] for x in y]
E.FEE
======================================================================
ERROR: test_jars_content_result_elements_are_generators (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1r9peqa/test.py", line 14, in test_jars_content_result_elements_are_generators
    cauliflowers=4
  File "/tmp/d20150331-20360-1r9peqa/solution.py", line 10, in jars_content
    content = [[a[i]+b[i]+c[i]+d[i]] for i in range(jars)]
  File "/tmp/d20150331-20360-1r9peqa/solution.py", line 10, in <listcomp>
    content = [[a[i]+b[i]+c[i]+d[i]] for i in range(jars)]
IndexError: list index out of range

======================================================================
ERROR: test_sample_test_with_easy_to_follow_products_distribution (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1r9peqa/test.py", line 37, in test_sample_test_with_easy_to_follow_products_distribution
    cauliflowers=4
  File "/tmp/d20150331-20360-1r9peqa/solution.py", line 10, in jars_content
    content = [[a[i]+b[i]+c[i]+d[i]] for i in range(jars)]
  File "/tmp/d20150331-20360-1r9peqa/solution.py", line 10, in <listcomp>
    content = [[a[i]+b[i]+c[i]+d[i]] for i in range(jars)]
IndexError: list index out of range

======================================================================
ERROR: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1r9peqa/test.py", line 66, in test_some_harder_to_follow_combos
    cauliflowers=32
  File "/tmp/d20150331-20360-1r9peqa/solution.py", line 10, in jars_content
    content = [[a[i]+b[i]+c[i]+d[i]] for i in range(jars)]
  File "/tmp/d20150331-20360-1r9peqa/solution.py", line 10, in <listcomp>
    content = [[a[i]+b[i]+c[i]+d[i]] for i in range(jars)]
IndexError: list index out of range

======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1r9peqa/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 4 != 3

----------------------------------------------------------------------
Ran 5 tests in 0.008s

FAILED (failures=1, errors=3)
Никола Терзиев
  • Некоректно
  • 2 успешни тест(а)
  • 3 неуспешни тест(а)
Никола Терзиев
from math import floor
from itertools import repeat
vegetable_constants = { 'bell_peppers' : 1, 'cauliflowers' : 2, 'carrots' : 4, 'celeries' : 3}
per_jar_bell_peppers = vegetable_constants['bell_peppers']
per_jar_cauliflowers = vegetable_constants['cauliflowers']
per_jar_carrots = vegetable_constants['carrots']
per_jar_celeries = vegetable_constants['celeries']
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
base_bell_peppers = get_base_material_in_jar(jars, 'bell_peppers', bell_peppers)
base_cauliflowers = get_base_material_in_jar(jars, 'cauliflowers', cauliflowers)
base_carrots = get_base_material_in_jar(jars, 'carrots', carrots)
base_celeries = get_base_material_in_jar(jars, 'celeries', celeries)
jar_generators = []
for jar in range(1, jars + 1):
jar_bell_peppers = base_bell_peppers + min(max((bell_peppers - base_bell_peppers * per_jar_bell_peppers -
(jar - 1)*per_jar_bell_peppers), 0), per_jar_bell_peppers)
jar_cauliflowers = base_bell_peppers + min(max((cauliflowers - base_cauliflowers * per_jar_cauliflowers -
(jar - 1)*per_jar_cauliflowers), 0), per_jar_cauliflowers)
jar_carrots = base_carrots + min(max((carrots - base_carrots * per_jar_carrots -
(jar - 1)*per_jar_carrots), 0), per_jar_carrots)
jar_celeries = base_celeries + min(max((celeries - base_celeries * per_jar_celeries -
(jar - 1)*per_jar_celeries), 0), per_jar_celeries)
products = list()
products.extend(list(repeat('bell_pepper', jar_bell_peppers)))
products.extend(list(repeat('cauliflower', jar_cauliflowers)))
products.extend(list(repeat('carrot', jar_carrots)))
products.extend(list(repeat('celery', jar_celeries)))
jar_generator = (x for x in products)
jar_generators.append(jar_generator)
return jar_generators
def get_base_material_in_jar(jars_amount, vegetable_name, vegetable_amount):
return floor(floor(vegetable_amount / vegetable_constants[vegetable_name]) / jars_amount) * \
vegetable_constants[vegetable_name]
..FFF
======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-u85sv3/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 1 != 3

======================================================================
FAIL: test_sample_test_with_easy_to_follow_products_distribution (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-u85sv3/test.py", line 40, in test_sample_test_with_easy_to_follow_products_distribution
    self.assertEqual(jar_content.count('bell_pepper'), 1)
AssertionError: 2 != 1

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-u85sv3/test.py", line 74, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('cauliflower'), 12)
AssertionError: 3 != 12

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=3)
Калоян Евтимов
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Калоян Евтимов
STOP = [1, 3, 7, 10]
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
pprs = ('bell_pepper' for x in range(bell_peppers))
cfl = ('cauliflower' for x in range(cauliflowers))
crrts = ('carrot' for x in range(carrots))
clr = ('celery' for x in range(celeries))
rule = [pprs, cfl, crrts, clr]
final_output = []
def items_to_put(pos_of_name):
new_pos_of_name = 0
for i in range(4):
if pos_of_name < STOP[i]:
new_pos_of_name = i
break
try:
output = next(rule[new_pos_of_name])
except StopIteration:
return ''
return output
for i in range(jars):
final_output.append((filter(lambda ch: ch != '',
(items_to_put(x) for x in range(10)))))
return final_output
..F.F
======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-hlaj9d/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 2 != 3

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-hlaj9d/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=2)
Димитър Влаховски
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Влаховски
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
ingredients = {
'bell_pepper': {'count': bell_peppers, 'per_jar': 1},
'cauliflower': {'count': cauliflowers, 'per_jar': 2},
'celery': {'count': celeries, 'per_jar': 3},
'carrot': {'count': carrots, 'per_jar': 4},
}
result = [[] for i in range(jars)]
while sum([ingredient['count']
for ingredient in ingredients.values()]) > 0:
for i in range(jars):
lst = []
for name, ingredient in ingredients.items():
if ingredient['count'] > 0:
count = min(ingredient['count'], ingredient['per_jar'])
lst.extend([name for i in range(count)])
ingredient['count'] -= count
result[i].extend(lst)
return list(map(lambda x: (i for i in x), result))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Цветан Мадански
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Мадански
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
temporary_result = []
for _ in range(jars):
temporary_result.append([])
current_jar = 0
while bell_peppers != 0 or cauliflowers != 0 or carrots != 0 or \
celeries != 0:
current = []
for _ in range(jars):
current.append([])
while current[current_jar].count('bell_pepper') < 1 and \
bell_peppers > 0:
current[current_jar].append('bell_pepper')
bell_peppers = bell_peppers - 1
while current[current_jar].count('cauliflower') < 2 and \
cauliflowers > 0:
current[current_jar].append('cauliflower')
cauliflowers = cauliflowers - 1
while current[current_jar].count('carrot') < 4 and carrots > 0:
current[current_jar].append('carrot')
carrots = carrots - 1
while current[current_jar].count('celery') < 3 and celeries > 0:
current[current_jar].append('celery')
celeries = celeries - 1
if current_jar == jars - 1:
current_jar = 0
else:
current_jar = current_jar + 1
for jar in range(jars):
for element in current[jar]:
temporary_result[jar].append(element)
result = []
for jar in range(jars):
result.append(iter(temporary_result[jar]))
return result
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Георги Павлов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Павлов
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
ingredients = [[bell_peppers, 1, 'bell_pepper'],
[cauliflowers, 2, 'cauliflower'],
[carrots, 4, 'carrot'],
[celeries, 3, 'celery']]
def get_min():
return min(ingredient[1], ingredient[0])
total_count = bell_peppers + cauliflowers + carrots + celeries
all_jars = [[] for _ in range(jars)]
while total_count:
for ingredient in ingredients:
for jar in all_jars:
if ingredient[0] > 0:
jar.extend([ingredient[2]] * get_min())
total_count -= get_min()
ingredient[0] -= get_min()
return [(vegetable for vegetable in jar) for jar in all_jars]
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Михаил Здравков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Михаил Здравков
VEGIES = ('bell_pepper', 1), ('cauliflower', 2), ('carrot', 4), ('celery', 3)
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
if jars <= 0:
return []
jar_list = [[] for _ in range(jars)]
vegies = [bell_peppers, cauliflowers, carrots, celeries]
jar_index = 0
while max(vegies) > 0:
for i in range(4):
if vegies[i] - VEGIES[i][1] >= 0:
jar_list[jar_index] += [VEGIES[i][0]] * VEGIES[i][1]
vegies[i] -= VEGIES[i][1]
else:
jar_list[jar_index] += [VEGIES[i][0]] * vegies[i]
vegies[i] = 0
jar_index += 1
if jar_index >= jars:
jar_index = 0
return [map(lambda x: x, jar) for jar in jar_list]
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Елица Илиева
  • Некоректно
  • 2 успешни тест(а)
  • 3 неуспешни тест(а)
Елица Илиева
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
full_jars = []
ingredients = {
'bell_pepper': {'needs': 1, 'has': bell_peppers},
'cauliflower': {'needs': 2, 'has': cauliflowers},
'carrot': {'needs': 4, 'has': carrots},
'celery': {'needs': 3, 'has': celeries}
}
def fill_jar(ingredient, stock):
can_use = min(stock[ingredient]['has'], stock[ingredient]['needs'])
stock[ingredient]['has'] -= can_use
return [ingredient for i in range(can_use)]
for jar_number in range(jars):
jar = []
for item in ingredients.items():
jar += fill_jar(item[0], ingredients)
full_jars.append(jar)
while sum(val['has'] for val in ingredients.values()):
for jar in full_jars:
for item in ingredient_mapper.items():
jar += fill_jar(item[0], item[1])
return [(el for el in iter(jar)) for jar in full_jars]
E.E.E
======================================================================
ERROR: test_jars_content_result_elements_are_generators (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-6robcz/test.py", line 14, in test_jars_content_result_elements_are_generators
    cauliflowers=4
  File "/tmp/d20150331-20360-6robcz/solution.py", line 21, in jars_content
    for item in ingredient_mapper.items():
NameError: name 'ingredient_mapper' is not defined

======================================================================
ERROR: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-6robcz/test.py", line 49, in test_sample_grandma_always_tries_to_take_fixed_combo
    cauliflowers=5
  File "/tmp/d20150331-20360-6robcz/solution.py", line 21, in jars_content
    for item in ingredient_mapper.items():
NameError: name 'ingredient_mapper' is not defined

======================================================================
ERROR: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-6robcz/test.py", line 66, in test_some_harder_to_follow_combos
    cauliflowers=32
  File "/tmp/d20150331-20360-6robcz/solution.py", line 21, in jars_content
    for item in ingredient_mapper.items():
NameError: name 'ingredient_mapper' is not defined

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (errors=3)
Цвета Кандиларова
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Цвета Кандиларова
def jar_content(jar, jars, bell_peppers, cauliflowers, carrots, celeries):
vegetables = {
'bell_pepper': 1,
'cauliflower': 2,
'celery': 3,
'carrot': 4
}
amount = {
'bell_pepper': bell_peppers,
'cauliflower': cauliflowers,
'celery': celeries,
'carrot': carrots
}
for v in vegetables:
doses = int(amount[v] / vegetables[v])
v_left = amount[v] % vegetables[v]
doses_per_jar = int(doses / jars)
d_left = doses % jars
if jar + 1 == d_left:
for i in range(0, int(((doses_per_jar + 1) * vegetables[v]))):
yield v
elif jar == d_left:
for i in range(0, int(doses_per_jar * vegetables[v] + v_left)):
yield v
else:
for i in range(0, doses_per_jar * vegetables[v]):
yield v
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
grannys_pickles = []
for jar in range(0, jars):
grannys_pickles.append(
jar_content(
jar, jars, bell_peppers, cauliflowers, carrots, celeries))
return grannys_pickles
....F
======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-7c3hne/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=1)
Илиан Стаменов
  • Некоректно
  • 0 успешни тест(а)
  • 5 неуспешни тест(а)
Илиан Стаменов
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
maximum_iterations = max(map(len, [bell_peppers, cauliflowers / 2,
carrots / 4, celeries / 3])) + 1
bell_peppers = ['bell_pepper' for i in range(bell_peppers)]
cauliflowers = ['cauliflower' for i in range(cauliflowers)]
carrots = ['carrot' for i in range(carrots)]
celeries = ['celery' for i in range(celeries)]
processed_jars = [list() for i in range(jars)]
for i in range(0, maximum_iterations):
ingredients = bell_peppers[:1] + cauliflowers[:2] \
+ carrots[:4] + celeries[:3]
processed_jars[i % jars].extend(ingredients)
del bell_peppers[:1], cauliflowers[:2], carrots[:4], celeries[:3]
return list(map(iter, processed_jars))
EEEEE
======================================================================
ERROR: test_jars_content_result_elements_are_generators (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1cuml2c/test.py", line 14, in test_jars_content_result_elements_are_generators
    cauliflowers=4
  File "/tmp/d20150331-20360-1cuml2c/solution.py", line 3, in jars_content
    carrots / 4, celeries / 3])) + 1
TypeError: object of type 'int' has no len()

======================================================================
ERROR: test_no_product_no_jars_content (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1cuml2c/test.py", line 27, in test_no_product_no_jars_content
    cauliflowers=0
  File "/tmp/d20150331-20360-1cuml2c/solution.py", line 3, in jars_content
    carrots / 4, celeries / 3])) + 1
TypeError: object of type 'int' has no len()

======================================================================
ERROR: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1cuml2c/test.py", line 49, in test_sample_grandma_always_tries_to_take_fixed_combo
    cauliflowers=5
  File "/tmp/d20150331-20360-1cuml2c/solution.py", line 3, in jars_content
    carrots / 4, celeries / 3])) + 1
TypeError: object of type 'int' has no len()

======================================================================
ERROR: test_sample_test_with_easy_to_follow_products_distribution (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1cuml2c/test.py", line 37, in test_sample_test_with_easy_to_follow_products_distribution
    cauliflowers=4
  File "/tmp/d20150331-20360-1cuml2c/solution.py", line 3, in jars_content
    carrots / 4, celeries / 3])) + 1
TypeError: object of type 'int' has no len()

======================================================================
ERROR: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1cuml2c/test.py", line 66, in test_some_harder_to_follow_combos
    cauliflowers=32
  File "/tmp/d20150331-20360-1cuml2c/solution.py", line 3, in jars_content
    carrots / 4, celeries / 3])) + 1
TypeError: object of type 'int' has no len()

----------------------------------------------------------------------
Ran 5 tests in 0.008s

FAILED (errors=5)
Николай Велков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Велков
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
matrix = [[] for _ in range(jars)]
i = 0
while bell_peppers > 0 or cauliflowers > 0 or carrots > 0 or celeries > 0:
if bell_peppers > 0:
matrix[i].append('bell_pepper')
bell_peppers = bell_peppers - 1
if cauliflowers < 2:
matrix[i].extend(['cauliflower' for _ in range(cauliflowers)])
cauliflowers = 0
else:
matrix[i].extend(['cauliflower' for _ in range(2)])
cauliflowers = cauliflowers - 2
if carrots < 4:
matrix[i].extend(['carrot' for _ in range(carrots)])
carrots = 0
else:
matrix[i].extend(['carrot' for _ in range(4)])
carrots = carrots - 4
if celeries < 3:
matrix[i].extend(['celery' for _ in range(celeries)])
celeries = 0
else:
matrix[i].extend(['celery' for _ in range(3)])
celeries = celeries - 3
i = i + 1
i = i % jars
return [(vegetable for vegetable in jar) for jar in matrix]
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Цветан Коев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Коев
def jar_generator(bell_peppers, cauliflowers, carrots, celeries):
for _ in range(bell_peppers):
yield "bell_pepper"
for _ in range(cauliflowers):
yield "cauliflower"
for _ in range(carrots):
yield "carrot"
for _ in range(celeries):
yield "celery"
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
jar_list = []
bell_peppers_by_jar = split_to_jars(jars, bell_peppers, 1)
cauliflowers_by_jar = split_to_jars(jars, cauliflowers, 2)
carrots_by_jar = split_to_jars(jars, carrots, 4)
celeries_by_jar = split_to_jars(jars, celeries, 3)
for i in range(jars):
jar_list.append(jar_generator(bell_peppers_by_jar[i],
cauliflowers_by_jar[i],
carrots_by_jar[i],
celeries_by_jar[i]))
return jar_list
def split_to_jars(jar_number, ingredients, step):
jars = [0] * jar_number
current = 0
while ingredients > 0:
current_jar = current % jar_number
jars[current_jar] += step if step <= ingredients else ingredients
ingredients -= step
current += 1
return jars
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Александър Наджарян
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Наджарян
import itertools
AMOUNT = {'bell_peppers': 1, 'cauliflowers': 2, 'carrots': 4, 'celeries': 3}
NAMES = {
'bell_peppers': 'bell_pepper',
'cauliflowers': 'cauliflower',
'carrots': 'carrot',
'celeries': 'celery'}
def ingredient_count(current_jar, jars, ingredient, quantity):
amount = AMOUNT[ingredient]
last_jar = quantity % (amount * jars) / amount
remainder = (current_jar < last_jar < current_jar+1) * (quantity % amount)
last_iteration = (last_jar >= current_jar + 1) * amount
complete_iterations = (quantity // (amount * jars)) * amount
final = complete_iterations + remainder + last_iteration
return [NAMES[ingredient]] * final
def jars_content(jars, **ingredients):
result = []
for jar in range(jars):
result.append([])
for ingredient in ingredients:
args = [jar, jars, ingredient, ingredients[ingredient]]
amount_in_jar = ingredient_count(*args)
result[jar] = list(itertools.chain(result[jar], amount_in_jar))
return list(map(iter, result))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Мартин Пацов
  • Некоректно
  • 0 успешни тест(а)
  • 5 неуспешни тест(а)
Мартин Пацов
def ingr_count(ingr, number):
value = 0
while value <= number:
yield ingr
value += 1
raise StopIteration
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
jars_ = []
for jar in range(jars):
jars_.append([])
for jar2 in jars_:
for i in range(4):
jar2.append(0)
while bell_peppers > 0 and cauliflowers > 0 and \
carrots > 0 and celeries > 0:
for i in range(jars):
if bell_peppers - 1 > 0:
jars_[i][0] += 1
bell_peppers -= 1
elif bell_peppers < 0:
pass
else:
jars_[i][0] += bell_peppers
bell_peppers -= 1
if cauliflowers - 2 > 0:
jars_[i][1] += 2
cauliflowers -= 2
elif cauliflowers < 0:
pass
else:
jars_[i][1] += cauliflowers
cauliflowers -= 2
if carrots - 4 > 0:
jars_[i][2] += 4
carrots -= 4
elif carrots < 0:
pass
else:
jars_[i][2] += carrots
carrots -= 4
if celeries - 3 > 0:
jars_[i][3] += 3
celeries -= 3
elif celeries < 0:
pass
else:
jars_[i][3] += celeries
celeries -= 3
return_jar = []
for jar in range(jars):
return_jar.append([
ingr_count('bell_pepper', jars_[jar][0]),
ingr_count('cauliflowers', jars_[jar][1]),
ingr_count('carrots', jars_[jar][2]),
ingr_count('celeries', jars_[jar][3])
])
return(return_jar)
FFFFF
======================================================================
FAIL: test_jars_content_result_elements_are_generators (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1kicmw9/test.py", line 17, in test_jars_content_result_elements_are_generators
    self.assertTrue(hasattr(jar, '__next__'))
AssertionError: False is not true

======================================================================
FAIL: test_no_product_no_jars_content (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1kicmw9/test.py", line 29, in test_no_product_no_jars_content
    self.assertEqual(len(list(jar)), 0)
AssertionError: 4 != 0

======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1kicmw9/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 0 != 3

======================================================================
FAIL: test_sample_test_with_easy_to_follow_products_distribution (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1kicmw9/test.py", line 40, in test_sample_test_with_easy_to_follow_products_distribution
    self.assertEqual(jar_content.count('bell_pepper'), 1)
AssertionError: 0 != 1

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-1kicmw9/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 0 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.008s

FAILED (failures=5)
Диана Генева
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Диана Генева
from itertools import chain
def take_vegetable(left, amount):
taken = []
for _ in range(amount):
if left:
taken.append(left.pop())
return taken
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
bell_peppers_left = ['bell_pepper'] * bell_peppers
cauliflowers_left = ['cauliflower'] * cauliflowers
carrots_left = ['carrot'] * carrots
celeries_left = ['celery'] * celeries
filled_jars = []
for jar in range(jars):
filled_jars.append(vegetable for vegetable in (
take_vegetable(bell_peppers_left, 1) +
take_vegetable(cauliflowers_left, 2) +
take_vegetable(carrots_left, 4) +
take_vegetable(celeries_left, 3)))
return filled_jars
..F.F
======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-yp98uo/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 2 != 3

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-yp98uo/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=2)
Ангел Ангелов
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Ангел Ангелов
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
if not jars:
return []
taken_bell_peppers = min(1, bell_peppers)
taken_cauliflowers = min(2, cauliflowers)
taken_carrots = min(4, carrots)
taken_celeries = min(3, celeries)
jar = (vegetable for vegetable in (['bell_pepper'] * taken_bell_peppers +
['cauliflower'] * taken_cauliflowers +
['carrot'] * taken_carrots +
['celery'] * taken_celeries))
return [jar] + jars_content(jars - 1,
bell_peppers - taken_bell_peppers,
cauliflowers - taken_cauliflowers,
carrots - taken_carrots,
celeries - taken_celeries)
..F.F
======================================================================
FAIL: test_sample_grandma_always_tries_to_take_fixed_combo (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-8gq5nq/test.py", line 54, in test_sample_grandma_always_tries_to_take_fixed_combo
    self.assertEqual(first_jar_content.count('cauliflower'), 3)
AssertionError: 2 != 3

======================================================================
FAIL: test_some_harder_to_follow_combos (test.TestGrandmaPickles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150331-20360-8gq5nq/test.py", line 73, in test_some_harder_to_follow_combos
    self.assertEqual(first_jar_content.count('bell_pepper'), 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=2)
Валентина Жекова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Валентина Жекова
from math import ceil
BELL_PEPPER_DOSAGE = 1
CAULIFLOWER_DOSAGE = 2
CARROTS_DOSAGE = 4
CELERIES_DOSAGE = 3
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
return [jar(index, jars, bell_peppers, cauliflowers, carrots, celeries)
for index in range(jars)]
def jar(index, jars, bell_peppers, cauliflowers, carrots, celeries):
bell_peppers_count = ingredient_count(bell_peppers, BELL_PEPPER_DOSAGE,
index, jars)
for i in range(bell_peppers_count):
yield "bell_pepper"
cauliflowers_count = ingredient_count(cauliflowers, CAULIFLOWER_DOSAGE,
index, jars)
for i in range(cauliflowers_count):
yield "cauliflower"
carrots_count = ingredient_count(carrots, CARROTS_DOSAGE, index, jars)
for i in range(carrots_count):
yield "carrot"
celeries_count = ingredient_count(celeries, CELERIES_DOSAGE, index, jars)
for i in range(celeries_count):
yield "celery"
def ingredient_count(total_count, dosage, jar_index, jars):
correction = -total_count % dosage
dosages_count = ceil(total_count / dosage)
average_dosages_per_jar = dosages_count // jars
if jar_index + 1 <= dosages_count % jars:
average_dosages_per_jar += 1
result = dosage * average_dosages_per_jar
if (dosages_count % jars == 0) and (jar_index == jars - 1):
result -= correction
elif jar_index + 1 == dosages_count % jars:
result -= correction
return result
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Людмил Делчев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Людмил Делчев
from itertools import repeat
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
jars_products = []
for _ in range(jars):
jars_products.append([])
while(bell_peppers > 0 or cauliflowers > 0 or carrots > 0 or celeries > 0):
for jar_index in range(jars):
add = (min(bell_peppers, 1))
jars_products[jar_index].extend(list(repeat('bell_pepper', add)))
bell_peppers -= add
add = (min(cauliflowers, 2))
jars_products[jar_index].extend(list(repeat('cauliflower', add)))
cauliflowers -= add
add = (min(carrots, 4))
jars_products[jar_index].extend(list(repeat('carrot', add)))
carrots -= add
add = (min(celeries, 3))
jars_products[jar_index].extend(list(repeat('celery', add)))
celeries -= add
return list(map(iter, jars_products))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Александър Ваканин
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Ваканин
import itertools
def jars_content(jars, bell_peppers, cauliflowers, carrots, celeries):
grandma_jars = []
all_grandma_vegetables = list(
jars_help(bell_peppers, cauliflowers, carrots, celeries))
for index in range(jars):
grandma_jars.insert(index,
iter([elem for i, elem in enumerate(all_grandma_vegetables)
if index * 10 <= i % (jars * 10) < (index + 1) * 10]))
return grandma_jars
def jars_help(bell_peppers, cauliflowers, carrots, celeries):
while any([bell_peppers, cauliflowers, carrots, celeries]):
if bell_peppers:
bell_peppers -= 1
yield 'bell_pepper'
elif bell_peppers == 0:
yield 'zero'
for _ in range(2):
if cauliflowers:
cauliflowers -= 1
yield 'cauliflower'
else:
yield 'zero'
for _ in range(4):
if carrots:
carrots -= 1
yield 'carrot'
else:
yield 'zero'
for _ in range(3):
if celeries:
celeries -= 1
yield 'celery'
else:
yield 'zero'
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK