Нонограма

Краен срок
17.04.2014 23:59

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

Нонограма (още японска кръстословица) е логическа игра, чиято цел е да разберете кои квадратчета трябва да се запълнят и кои не, като се взимат под внимание числата дадени по краищата на решетката.

nonogram

За целта в ляво на всеки ред и в горната част на всяка колона има поредица от числа. Те указват бройката на последователните черни квадратчета съответно по хоризонтала и вертикала.

Например:

  • числата в първия ред 1 1 1 означават, че в този ред има 3 групи запълнени квадратчета. Всяка група се състои от по едно запълнено квадратче и всеки 2 групи са разделени с поне едно незапълнено квадратче

  • числата в първата колона 1 3 означават, че в тази колона има 2 групи запълнени квадратчет: първата група се състои от 1 запълнено квадратче, а втората група от 3 последователни запълнени квадратчета. Всяка група е разделена с поне едно незапълнено квадратче. Последователността на числата указва последователността на групите.

Нашата задача

Да напишем валидатор на нонограми(функция validate_nonogram), който по дадена нонограма да казва дали е правилно решена, или не.

Как ще представяме една нонограма

  • матрица(списък от списъци), която ще представлява решетката от запълнени и незапълнени квадратчета

  • речник с два ключа 'rows' и 'columns', като за всеки ключ имаме списък от списъци със ключовете в даден ред/колона

Пример

>>> nonogram = [[' ', ' ', ' ', 'X', ' '],
                [' ', 'X', 'X', 'X', 'X'],
                ['X', 'X', 'X', ' ', 'X'],
                ['X', 'X', 'X', ' ', ' '],
                ['X', ' ', ' ', ' ', ' ']]
>>>
>>> keys = {'rows': [[1], [4], [3, 1], [3], [1]],
            'columns': [[3], [3], [3], [2], [2]]}
>>>
>>> validate_nonogram(nonogram, keys)
True
  • всеки списък в nonogram е един ред от нонограмата
  • ' ' означава незапълнено квадратче
  • 'X' означава запълнено квадратче
  • keys['rows'][0] съдържа всички ключове от първия ред
  • keys['columns'][3] съдържа всички ключове от четвъртата колона

Test sneak peak

Python

python

Ruby

ruby

Тук може да си поиграете и нарисувате свои нонограми, които директно се превръщат в тестове(е да, играчка си е да препишете голяма нонограма, но е яко :satisfied:).

Решения

Йосиф Цветков
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Йосиф Цветков
from re import match
def validate_nonogram(nonogram, keys):
transposed_nonogram = list(zip(*nonogram))
for rows_cols, lists in keys.items():
for index, list_i in enumerate(lists):
regex = r''
string = ''.join(nonogram[index]) if rows_cols == 'rows' else\
''.join(transposed_nonogram[index])
for number in list_i:
regex += ' *X{%d}' % number
regex += ' *'
if not (match(regex, string) != None and
match(regex, string).group() == string):
return False
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.040s

OK
Димитър Чаушев
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Димитър Чаушев
def validate_nonogram(nonogram, keys):
trans_nonogram = matrixTranspose(nonogram)
rows = []
for index, row in enumerate(keys['rows']):
rows.append(check_nonogram(len(row), index, nonogram))
cols = []
for index, col in enumerate(keys['columns']):
cols.append(check_nonogram(len(col), index, trans_nonogram))
if rows == keys['rows'] and cols == keys['columns']:
return True
return False
def matrixTranspose(anArray):
transposed = [None]*len(anArray[0])
for t in range(len(anArray)):
transposed[t] = [None]*len(anArray)
for tt in range(len(anArray[t])):
transposed[t][tt] = anArray[tt][t]
return(transposed)
def check_nonogram(n, ind, nonogram):
start = nonogram[ind].index('X')
end = len(nonogram[ind])
cnt = 0
ans = []
j = start
while(j < end - 1):
for i in range(start, end):
if(i < end - 1 and nonogram[ind][i] == 'X'):
cnt += 1
elif i == end - 1 and nonogram[ind][i] == 'X':
cnt += 1
if(cnt != 0):
ans.append(cnt)
return ans
elif nonogram[ind][i] == ' ':
start = i + 1
if(cnt != 0):
ans.append(cnt)
cnt = 0
elif i == end - 1 and nonogram[ind][i] == ' ':
if(cnt != 0):
ans.append(cnt)
return ans
j += 1
if(cnt != 0):
ans.append(cnt)
return ans
..E...
======================================================================
ERROR: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-94ox0k/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-94ox0k/solution.py", line 3, in validate_nonogram
    trans_nonogram = matrixTranspose(nonogram)
  File "/tmp/d20140423-11348-94ox0k/solution.py", line 24, in matrixTranspose
    transposed[t][tt] = anArray[tt][t]
IndexError: list index out of range

----------------------------------------------------------------------
Ran 6 tests in 0.009s

FAILED (errors=1)
Никола Ненков
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Ненков
from functools import reduce
import re
def is_row_valid(row, row_keys):
string_keys = [str(key) for key in row_keys]
pattern = reduce(lambda so_far, next_key: '{}X{{{}}} +'.format(so_far, next_key), string_keys, '^ *')
pattern = pattern[:-1] + '*$'
return bool(re.search(pattern, ''.join(row)))
def validate_nonogram(nonogram, keys):
rows_valid = all(is_row_valid(nonogram[index], row_keys)
for index, row_keys in enumerate(keys['rows']))
columns_valid = all(is_row_valid(list(zip(*nonogram))[index], columns_keys)
for index, columns_keys in enumerate(keys['columns']))
return rows_valid and columns_valid
......
----------------------------------------------------------------------
Ran 6 tests in 0.043s

OK
Стефани Цакова
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Стефани Цакова
import re
def validate_rows(nonogram, keys):
for row in range(len(keys['rows'])):
expression = "^\s{0,}"
for i in range(len(keys["rows"][row])):
expression += keys["rows"][row][i] * 'X'
if i < len(keys["rows"][row]) - 1:
expression += '\s+'
expression += "\s{0,}$"
if not re.search(expression, ''.join(nonogram[row])):
return False
return True
def validate_cols(nonogram, keys):
for col in range(len(keys['columns'])):
expression = "^\s{0,}"
for i in range(len(keys["columns"][col])):
expression += keys["columns"][col][i] * 'X'
if i < len(keys["columns"][col]) - 1:
expression += '\s+'
expression += "\s{0,}$"
current_collumn = [row[col] for row in nonogram]
if not re.search(expression, ''.join(current_collumn)):
return False
return True
def validate_nonogram(nonogram, keys):
return validate_cols(nonogram, keys) and validate_rows(nonogram, keys)
......
----------------------------------------------------------------------
Ran 6 tests in 0.039s

OK
Ралица Цанова
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Ралица Цанова
import re
def generate_regex(list_):
regex = '\s*'
for number in list_:
regex += 'X{}'.format('{' + str(number) + '}\s+')
return regex[:len(regex) - 1] + "*"
def transform_into_regex(data):
return [generate_regex(element) for element in data]
def test(nonogram, data):
data = transform_into_regex(data)
for i, j in zip(data, nonogram):
match = re.match(r'{}'.format(i), ''.join(j))
if match is None or match.group() != ''.join(j):
return False
return True
def validate_nonogram(nonogram, keys):
test_rows = test(nonogram, keys['rows'])
return test_rows and test(zip(*nonogram), keys['columns'])
......
----------------------------------------------------------------------
Ran 6 tests in 0.041s

OK
Тихомир Янев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Тихомир Янев
def validate_nonogram(nonogram, keys):
col_size = len(nonogram[0])
col_list = [[z[y] for z in nonogram] for y in range(col_size)]
return [sum(z) for z in keys['rows']] == [
z.count('X') for z in nonogram] and [
sum(z) for z in keys['columns']] == [
z.count('X') for z in col_list]
......
----------------------------------------------------------------------
Ran 6 tests in 0.004s

OK
Драгомир Тунчев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Драгомир Тунчев
import re
def validate_row(row, keys):
expr = r'^\s*'
for index in range(len(keys)):
expr = '{}{}'.format(expr, '{}{}{}'.format('X{', keys[index], '}\s+'))
return re.match('{}{}'.format(expr, '$'),
'{}{}'.format(''.join(row), ' '),
flags=re.IGNORECASE)
def validate_rows(nonogram, keys):
return all([validate_row(nonogram[row], keys[row])
for row in range(len(nonogram))])
def validate_nonogram(nonogram, keys):
return (validate_rows(nonogram, keys['rows']) and
validate_rows(list(map(list, zip(*nonogram))), keys['columns']))
......
----------------------------------------------------------------------
Ran 6 tests in 0.045s

OK
Георги Стайков
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Стайков
import re
def get_column(nonogram, number):
return list(zip(*nonogram))[number]
def validate_line(line, key_list):
expression = "^\s*"
for key in key_list:
expression += 'X{}'.format('{' + str(key) + '}') + '\s+'
expression = list(expression)
expression[-1] = '*$'
expression = ''.join(expression)
return re.match(expression, ''.join(line))
def validate_nonogram(nonogram, keys):
line = 0
for key_list in keys['rows']:
if not validate_line(nonogram[line], key_list):
return False
line += 1
column = 0
for key_list in keys['columns']:
if not validate_line(get_column(nonogram, column), key_list):
return False
column += 1
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.046s

OK
Георги Димитров
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Димитров
import re
def get_squares_info(iterable):
keys = [len(sequence) for sequence in re.findall(r'X+', ''.join(iterable))]
if keys:
return keys
return [0]
def validate_nonogram(nonogram, keys):
rows = [get_squares_info(row) for row in nonogram]
cols = [get_squares_info(col) for col in list(zip(*nonogram))]
return rows == keys['rows'] and cols == keys['columns']
......
----------------------------------------------------------------------
Ran 6 tests in 0.009s

OK
Димитър Мутафчиев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Мутафчиев
import re
def validate_nonogram(nonogram, keys):
rows_strings = [''.join(i) for i in nonogram]
columns_strings = [''.join(i) for i in zip(*nonogram)]
regex = {'rows': [make_regex(l) for l in keys['rows']],
'columns': [make_regex(l) for l in keys['columns']]}
rows_matches = list(map(re.match, regex['rows'], rows_strings))
columns_matches = list(map(re.match, regex['columns'], columns_strings))
return all(rows_matches) and all(columns_matches)
def make_regex(mask):
result = r'^ *'
for n in mask[:len(mask)-1]:
result += r'X{' + str(n) + '} +'
result += r'X{' + str(mask[-1]) + '} *'
result += r'$'
return result
......
----------------------------------------------------------------------
Ran 6 tests in 0.037s

OK
Марио Димитров
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Марио Димитров
import re
def validate_direction(nonogram, key):
pattern = 'X+'
counts = []
for i in range(len(nonogram)):
array = re.findall(pattern, ''.join(nonogram[i]))
if array != []:
counts.append(list(map(lambda x: len(x), array)))
else:
counts.append([0])
return key == counts
def validate_nonogram(nonogram, keys):
transposed = list(zip(*nonogram))
return validate_direction(nonogram, keys['rows']) and validate_direction(transposed, keys['columns'])
......
----------------------------------------------------------------------
Ran 6 tests in 0.010s

OK
Никола Димитров
  • Некоректно
  • 0 успешни тест(а)
  • 6 неуспешни тест(а)
Никола Димитров
import re
X_SYMBOL = 'X'
def transpose(matrix):
return list(zip(*matrix))
def key_to_pattern(key):
transform_block = lambda block: "{0}{{{1}}}".format(X_SYMBOL, block)
return "^ *" + " +".join(map(transform_block, key)) + " *$"
def validate_sequence(sequence, key):
string_sequence = "".join(sequence)
pattern = key_to_pattern(key)
return re.match(pattern, string_sequence)
def validate_all_sequences(nonogram, keys, key_name):
return all([validate_sequence(row, keys[key_name][index]) for index, row in enumerate(nonogram)])
def validate_nonogram(nongram, keys):
return (validate_all_sequences(nonogram, keys, "rows") and
validate_all_sequences(transpose(nonogram), keys, "columns"))
EEEEEE
======================================================================
ERROR: test_error_in_columns (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-uo03c8/test.py", line 41, in test_error_in_columns
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-uo03c8/solution.py", line 25, in validate_nonogram
    return (validate_all_sequences(nonogram, keys, "rows") and
NameError: global name 'nonogram' is not defined

======================================================================
ERROR: test_error_in_rows (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-uo03c8/test.py", line 29, in test_error_in_rows
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-uo03c8/solution.py", line 25, in validate_nonogram
    return (validate_all_sequences(nonogram, keys, "rows") and
NameError: global name 'nonogram' is not defined

======================================================================
ERROR: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-uo03c8/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-uo03c8/solution.py", line 25, in validate_nonogram
    return (validate_all_sequences(nonogram, keys, "rows") and
NameError: global name 'nonogram' is not defined

======================================================================
ERROR: test_python_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-uo03c8/test.py", line 165, in test_python_nonogram
    python_keys))
  File "/tmp/d20140423-11348-uo03c8/solution.py", line 25, in validate_nonogram
    return (validate_all_sequences(nonogram, keys, "rows") and
NameError: global name 'nonogram' is not defined

======================================================================
ERROR: test_ruby_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-uo03c8/test.py", line 285, in test_ruby_nonogram
    self.assertTrue(solution.validate_nonogram(ruby_nonogram, ruby_keys))
  File "/tmp/d20140423-11348-uo03c8/solution.py", line 25, in validate_nonogram
    return (validate_all_sequences(nonogram, keys, "rows") and
NameError: global name 'nonogram' is not defined

======================================================================
ERROR: test_valid_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-uo03c8/test.py", line 17, in test_valid_nonogram
    self.assertTrue(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-uo03c8/solution.py", line 25, in validate_nonogram
    return (validate_all_sequences(nonogram, keys, "rows") and
NameError: global name 'nonogram' is not defined

----------------------------------------------------------------------
Ran 6 tests in 0.006s

FAILED (errors=6)
Филип Митов
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Филип Митов
def validate_nonogram(nonogram, keys):
is_correct = []
for index in range(len(nonogram)):
filled_squares_number = nonogram[index].count('X')
is_correct.append(filled_squares_number == sum(keys['rows'][index]))
transposed_nonogram = [list(x) for x in zip(*nonogram)]
for index in range(len(transposed_nonogram)):
filled_squares_number = transposed_nonogram[index].count('X')
is_correct.append(filled_squares_number == sum(keys['columns'][index]))
return all(is_correct)
......
----------------------------------------------------------------------
Ran 6 tests in 0.004s

OK
Веселин Генадиев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Веселин Генадиев
from re import match
def validate_line(line, key):
format_block = lambda repeat_count: 'X{{{}}}'.format(repeat_count)
pattern = '{}{}{}'.format('^ *', ' +'.join(map(format_block, key)), ' *$')
return match(pattern, line)
def validate_nonogram(nonogram, keys):
row_patterns = [validate_line(''.join(nonogram[index]), key)
for index, key in enumerate(keys['rows'])]
transposed = list(zip(*nonogram))
column_patterns = [validate_line(''.join(transposed[index]), key)
for index, key in enumerate(keys['columns'])]
return all(row_patterns + column_patterns)
......
----------------------------------------------------------------------
Ran 6 tests in 0.040s

OK
Антон Стоянов
  • Некоректно
  • 0 успешни тест(а)
  • 6 неуспешни тест(а)
Антон Стоянов
import re
def construct_reg_ex(sequence):
reg_ex = "\s*"
for index, repetitions in enumerate(sequence):
reg_ex += 'X{' + str(repetitions) + '}'
if index != len(sequence) - 1:
reg_ex += "\s+"
else:
reg_ex += "\s*"
return reg_ex
def validate_nonogram(nonogram, keys):
# Check rows
for num_row, row in enumerate(keys['rows']):
reg_exp_row = construct_reg_ex(row)
match_found = re.fullmatch(reg_exp_row, "".join(nonogram[num_row]))
if not match_found:
return False
# Transpose nonogram
zipper = zip(*nonogram)
# Check columns
for col in keys['columns']:
reg_exp_col = construct_reg_ex(col)
row_config = "".join(next(zipper))
match_found = re.fullmatch(reg_exp_col, row_config)
if not match_found:
return False
return True
EEEEEE
======================================================================
ERROR: test_error_in_columns (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-18py362/test.py", line 41, in test_error_in_columns
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-18py362/solution.py", line 22, in validate_nonogram
    match_found = re.fullmatch(reg_exp_row, "".join(nonogram[num_row]))
AttributeError: 'module' object has no attribute 'fullmatch'

======================================================================
ERROR: test_error_in_rows (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-18py362/test.py", line 29, in test_error_in_rows
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-18py362/solution.py", line 22, in validate_nonogram
    match_found = re.fullmatch(reg_exp_row, "".join(nonogram[num_row]))
AttributeError: 'module' object has no attribute 'fullmatch'

======================================================================
ERROR: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-18py362/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-18py362/solution.py", line 22, in validate_nonogram
    match_found = re.fullmatch(reg_exp_row, "".join(nonogram[num_row]))
AttributeError: 'module' object has no attribute 'fullmatch'

======================================================================
ERROR: test_python_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-18py362/test.py", line 165, in test_python_nonogram
    python_keys))
  File "/tmp/d20140423-11348-18py362/solution.py", line 22, in validate_nonogram
    match_found = re.fullmatch(reg_exp_row, "".join(nonogram[num_row]))
AttributeError: 'module' object has no attribute 'fullmatch'

======================================================================
ERROR: test_ruby_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-18py362/test.py", line 285, in test_ruby_nonogram
    self.assertTrue(solution.validate_nonogram(ruby_nonogram, ruby_keys))
  File "/tmp/d20140423-11348-18py362/solution.py", line 22, in validate_nonogram
    match_found = re.fullmatch(reg_exp_row, "".join(nonogram[num_row]))
AttributeError: 'module' object has no attribute 'fullmatch'

======================================================================
ERROR: test_valid_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-18py362/test.py", line 17, in test_valid_nonogram
    self.assertTrue(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-18py362/solution.py", line 22, in validate_nonogram
    match_found = re.fullmatch(reg_exp_row, "".join(nonogram[num_row]))
AttributeError: 'module' object has no attribute 'fullmatch'

----------------------------------------------------------------------
Ran 6 tests in 0.006s

FAILED (errors=6)
Теодор Драганов
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Теодор Драганов
import re
def validate_nonogram(nonogram, keys):
rows_preview = nonogram
columns_preview = list(zip(*nonogram))
for row_index in range(len(keys['rows'])):
pattern = r''.join(['X{{{}}}\s*'.format(X_count)
for X_count in keys['rows'][row_index]])
string_to_check = ''.join(rows_preview[row_index])
result = re.search(pattern, string_to_check)
if result is None:
return False
for column_index in range(len(keys['columns'])):
pattern = r''.join(['X{{{}}}\s*'.format(X_count)
for X_count in keys['columns'][column_index]])
string_to_check = ''.join(columns_preview[column_index])
result = re.search(pattern, string_to_check)
if result is None:
return False
return True
..F...
======================================================================
FAIL: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-7r9nez/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 6 tests in 0.038s

FAILED (failures=1)
Йордан Дикманов
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Йордан Дикманов
import re
def validate_option(nonogram, keys, option):
p = re.compile('X+')
all_X_list = []
for index, row in enumerate(nonogram):
all_X_list = p.findall(''.join(row))
for index_in_all_X, count_X in enumerate(all_X_list):
if len(count_X) != keys[option][index][index_in_all_X]:
return False
return True
def validate_nonogram(nonogram, keys):
valid_rows = validate_option(nonogram, keys, "rows")
validate_columns = validate_option(list(zip(*nonogram)), keys, "columns")
return valid_rows and validate_columns
.E....
======================================================================
ERROR: test_error_in_rows (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-nn4s3e/test.py", line 29, in test_error_in_rows
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-nn4s3e/solution.py", line 16, in validate_nonogram
    valid_rows = validate_option(nonogram, keys, "rows")
  File "/tmp/d20140423-11348-nn4s3e/solution.py", line 10, in validate_option
    if len(count_X) != keys[option][index][index_in_all_X]:
IndexError: list index out of range

----------------------------------------------------------------------
Ran 6 tests in 0.006s

FAILED (errors=1)
Мартин Георгиев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Мартин Георгиев
def transpose(nonogram):
nonogram_transposed = []
for i in range(len(nonogram[0])):
column = []
for row in nonogram:
column.append(row[0])
del row[0]
nonogram_transposed.append(column)
return nonogram_transposed
def convert_row(nonogram):
row_num = []
for row in nonogram:
counter = 0
in_row = []
for element in row:
if element == 'X':
counter += 1
elif counter:
in_row.append(counter)
counter = 0
if counter:
in_row.append(counter)
if in_row == []:
in_row = [0]
row_num.append(in_row)
return row_num
def validate_nonogram(nonogram, keys):
rows = convert_row(nonogram)
columns = convert_row(transpose(nonogram))
return rows == keys['rows'] and columns == keys['columns']
......
----------------------------------------------------------------------
Ran 6 tests in 0.005s

OK
Цветислав Викторов
  • Некоректно
  • 0 успешни тест(а)
  • 6 неуспешни тест(а)
Цветислав Викторов
def valid_nonogram(matrix, keys):
current_row = 0
for row in keys['rows']:
if row != x_in_row_i(matrix,current_row):
return False
current_row = current_row + 1
current_col = 0
for col in keys['columns']:
if col != x_in_col_i(matrix,current_col):
print(col)
print(x_in_col_i(matrix,current_col))
print()
return False
current_col = current_col + 1
return True
def x_in_row_i(matrix, i):
current_row = 0
count = 0
x_list = []
for row in matrix:
if current_row == i:
for item in row:
if item == 'X':
count = count + 1
else:
if count > 0:
x_list.append(count)
count = 0
if count > 0:
x_list.append(count)
current_row = current_row + 1
if len(x_list) == 0:
x_list.append(0)
return x_list
def x_in_col_i(matrix, i):
count = 0
x_list = []
for item in col_i(matrix, i):
if item == 'X':
count = count + 1
else:
if count > 0:
x_list.append(count)
count = 0
if count > 0:
x_list.append(count)
if len(x_list) == 0:
x_list.append(0)
return x_list
def col_i(matrix, i):
items = []
for row in matrix:
items.append(row[i])
return items
EEEEEE
======================================================================
ERROR: test_error_in_columns (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-8ywf2f/test.py", line 41, in test_error_in_columns
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AttributeError: 'module' object has no attribute 'validate_nonogram'

======================================================================
ERROR: test_error_in_rows (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-8ywf2f/test.py", line 29, in test_error_in_rows
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AttributeError: 'module' object has no attribute 'validate_nonogram'

======================================================================
ERROR: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-8ywf2f/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AttributeError: 'module' object has no attribute 'validate_nonogram'

======================================================================
ERROR: test_python_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-8ywf2f/test.py", line 164, in test_python_nonogram
    self.assertTrue(solution.validate_nonogram(python_nonogram,
AttributeError: 'module' object has no attribute 'validate_nonogram'

======================================================================
ERROR: test_ruby_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-8ywf2f/test.py", line 285, in test_ruby_nonogram
    self.assertTrue(solution.validate_nonogram(ruby_nonogram, ruby_keys))
AttributeError: 'module' object has no attribute 'validate_nonogram'

======================================================================
ERROR: test_valid_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-8ywf2f/test.py", line 17, in test_valid_nonogram
    self.assertTrue(solution.validate_nonogram(nonogram, keys))
AttributeError: 'module' object has no attribute 'validate_nonogram'

----------------------------------------------------------------------
Ran 6 tests in 0.005s

FAILED (errors=6)
Гергана Петрова
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Гергана Петрова
def validate_nonogram(nonogram, keys):
for index, key in enumerate(keys['rows']):
if nonogram[index].count('X') != sum(key):
return False
transpose_nonogram = list(zip(*nonogram))
for index, key in enumerate(keys['columns']):
if transpose_nonogram[index].count('X') != sum(key):
return False
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.003s

OK
Цветелина Борисова
  • Некоректно
  • 4 успешни тест(а)
  • 2 неуспешни тест(а)
Цветелина Борисова
def validate_nonogram(nonogram, keys):
count_of_filled = {}
for key in keys:
count_of_filled[key] = [sum(cells) for cells in keys[key]]
for row_index, row in enumerate(nonogram):
for filled_index, filled in enumerate(row):
if filled == 'X':
count_of_filled['rows'][row_index] -= 1
count_of_filled['columns'][filled_index] -= 1
return sum(count_of_filled['rows']) == sum(count_of_filled['columns']) == 0
FF....
======================================================================
FAIL: test_error_in_columns (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1u6791y/test.py", line 41, in test_error_in_columns
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

======================================================================
FAIL: test_error_in_rows (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1u6791y/test.py", line 29, in test_error_in_rows
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 6 tests in 0.005s

FAILED (failures=2)
Петър Парушев
  • Некоректно
  • 0 успешни тест(а)
  • 6 неуспешни тест(а)
Петър Парушев
def validate_nonogram(nonogram, keys):
for legend in ('rows', 'columns'):
work_nonogram = nonogram
if legend != 'rows':
work_nonogram = list(zip(*nonogram))
for index, current_legend in enumerate(keys[legend]):
pattern = r''
for member_index, legend_member in enumerate(current_legend):
pattern += 'X{' + str(legend_member) + '}'
if member_index != (len(current_legend) - 1):
pattern += '\s+'
row_string = str()
for square in work_nonogram[index]:
row_string += square
if not re.search(pattern, row_string):
return False
return True
EEEEEE
======================================================================
ERROR: test_error_in_columns (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-g0112b/test.py", line 41, in test_error_in_columns
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-g0112b/solution.py", line 16, in validate_nonogram
    if not re.search(pattern, row_string):
NameError: global name 're' is not defined

======================================================================
ERROR: test_error_in_rows (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-g0112b/test.py", line 29, in test_error_in_rows
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-g0112b/solution.py", line 16, in validate_nonogram
    if not re.search(pattern, row_string):
NameError: global name 're' is not defined

======================================================================
ERROR: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-g0112b/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-g0112b/solution.py", line 16, in validate_nonogram
    if not re.search(pattern, row_string):
NameError: global name 're' is not defined

======================================================================
ERROR: test_python_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-g0112b/test.py", line 165, in test_python_nonogram
    python_keys))
  File "/tmp/d20140423-11348-g0112b/solution.py", line 16, in validate_nonogram
    if not re.search(pattern, row_string):
NameError: global name 're' is not defined

======================================================================
ERROR: test_ruby_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-g0112b/test.py", line 285, in test_ruby_nonogram
    self.assertTrue(solution.validate_nonogram(ruby_nonogram, ruby_keys))
  File "/tmp/d20140423-11348-g0112b/solution.py", line 16, in validate_nonogram
    if not re.search(pattern, row_string):
NameError: global name 're' is not defined

======================================================================
ERROR: test_valid_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-g0112b/test.py", line 17, in test_valid_nonogram
    self.assertTrue(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-g0112b/solution.py", line 16, in validate_nonogram
    if not re.search(pattern, row_string):
NameError: global name 're' is not defined

----------------------------------------------------------------------
Ran 6 tests in 0.006s

FAILED (errors=6)
Милен Христов
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Милен Христов
def validate_nonogram(nonogram, keys):
result_keys = {'rows': [],
'columns': []}
for row in nonogram:
rows_items = []
items_in_group = 0
for item in range(0, len(row)):
if row[item] == 'X':
items_in_group += 1
else:
if items_in_group != 0:
rows_items.append(items_in_group)
items_in_group = 0
if items_in_group != 0 and item == len(row)-1:
rows_items.append(items_in_group)
if len(rows_items) == 0:
rows_items.append(0)
result_keys['rows'].append(rows_items)
col_len = len(nonogram)
row_len = len(nonogram[0])
for col in range(0, row_len):
cols_items = []
items_in_group = 0
for row in range(0, col_len):
if nonogram[row][col] == 'X':
items_in_group += 1
else:
if items_in_group != 0:
cols_items.append(items_in_group)
items_in_group = 0
if items_in_group != 0 and row == col_len - 1:
cols_items.append(items_in_group)
if len(cols_items) == 0:
cols_items.append(0)
result_keys['columns'].append(cols_items)
if result_keys == keys:
return True
return False
......
----------------------------------------------------------------------
Ran 6 tests in 0.005s

OK
Емилиан Станков
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Емилиан Станков
def validate_nonogram(nonogram, keys):
rows_answer = []
columns_answer = []
for i in range(len(nonogram)):
consecutive = 0
current_row = []
for j in range(len(nonogram[i])):
if nonogram[i][j] == 'X':
consecutive += 1
else:
if consecutive != 0:
current_row.append(consecutive)
consecutive = 0
if consecutive != 0:
current_row.append(consecutive)
if current_row == []:
current_row = [0]
rows_answer.append(current_row)
for i in range(len(nonogram[1])):
consecutive = 0
current_column = []
for j in range(len(nonogram)):
if nonogram[j][i] == 'X':
consecutive += 1
else:
if consecutive != 0:
current_column.append(consecutive)
consecutive = 0
if consecutive != 0:
current_column.append(consecutive)
if current_column == []:
current_column = [0]
columns_answer.append(current_column)
if keys['rows'] == rows_answer and keys['columns'] == columns_answer:
return True
return False
......
----------------------------------------------------------------------
Ran 6 tests in 0.005s

OK
Иван Бобев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Бобев
import re
def build_regex(key):
regex_str = '^ *'
for i in range(len(key) - 1):
regex_str += 'X{%s} +' % key[i]
regex_str += 'X{%s} *$' % key[-1]
return re.compile(regex_str)
def validate_row(row, key):
regex = build_regex(key)
return regex.match(''.join(row))
def is_valid(nonogram, keys):
for row, key in zip(nonogram, keys):
if not validate_row(row, key):
return False
return True
def validate_nonogram(nonogram, keys):
return is_valid(nonogram, keys['rows']) and \
is_valid(zip(*nonogram), keys['columns'])
......
----------------------------------------------------------------------
Ran 6 tests in 0.039s

OK
Мария Донева
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Донева
import re
def is_valid_nonogram(count_of_groups, line):
regExp = r''
is_matched = False
for count_of_Xs in count_of_groups:
regExp += r'\s*X{' + '{}'.format(count_of_Xs) + r'}\s*'
matchObj = re.match(regExp, line, re.I)
if matchObj:
if matchObj.group() == line:
is_matched = True
else:
is_matched = False
return is_matched
def validate_nonogram(nonogram, keys):
count_rows = len(nonogram)
count_columns = len(nonogram[0])
is_matched_on_rows = False
is_matched_on_columns = False
for row in range(count_rows):
line = ''.join(nonogram[row])
count_of_groups = keys['rows'][row]
is_matched_on_rows = is_valid_nonogram(count_of_groups, line)
if is_matched_on_rows is False:
break
for column in range(count_columns):
line = ''.join([row[column] for row in nonogram])
count_of_groups = keys['columns'][column]
is_matched_on_columns = is_valid_nonogram(count_of_groups, line)
if is_matched_on_columns is False:
break
return is_matched_on_rows and is_matched_on_columns
......
----------------------------------------------------------------------
Ran 6 tests in 0.050s

OK
Александър Златков
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Златков
FILLED_CELL = 'X'
ROWS_KEY = 'rows'
COLUMNS_KEY = 'columns'
def is_filled_cell(cell):
return cell == FILLED_CELL
def calculate_block_sizes(segment):
block_size = 0
block_sizes = []
for element in segment:
if is_filled_cell(element):
block_size += 1
elif block_size > 0:
block_sizes.append(block_size)
block_size = 0
if block_size > 0:
block_sizes.append(block_size)
return block_sizes
def validate_segment(segment, block_sizes):
segment_block_sizes = calculate_block_sizes(segment)
filtered_block_sizes = [x for x in block_sizes if x > 0]
block_sizes_count = len(filtered_block_sizes)
if len(segment_block_sizes) != block_sizes_count:
return False
for i in range(block_sizes_count):
if segment_block_sizes[i] != filtered_block_sizes[i]:
return False
return True
def validate_nonogram(nonogram, keys):
rows_count = len(nonogram)
columns_count = len(nonogram[0]) if rows_count > 0 else 0
for i in range(rows_count):
if not validate_segment(nonogram[i], keys[ROWS_KEY][i]):
return False
for i in range(columns_count):
column = [row[i] for row in nonogram]
if not validate_segment(column, keys[COLUMNS_KEY][i]):
return False
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.006s

OK
Антонио Николов
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Антонио Николов
def count_x(nonogram_row):
nonogram_row.append(' ')
new_row = []
count = 0
for element in nonogram_row:
if element == 'X':
count += 1
elif count != 0:
new_row.append(count)
count = 0
if not new_row:
new_row.append(0)
return new_row
def validate_nonogram(nonogram, keys):
rows = list(map(count_x, nonogram))
columns = list(map(count_x, list(map(list, zip(*nonogram)))))
return rows == keys['rows'] and columns[0:-1] == keys['columns']
......
----------------------------------------------------------------------
Ran 6 tests in 0.008s

OK
Иван Георгиев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Георгиев
def transform(row):
result = []
count = 0
for symbol in row:
if symbol == 'X':
count+=1
else:
result.append(count)
count = 0
result.append(count)
nrow = [symbol for symbol in result if symbol]
if nrow == []:
nrow.append(0)
return nrow
def validate_nonogram(nonogram, keys):
nrows, ncolumns = [], []
[nrows.append(transform(row)) for row in nonogram]
[ncolumns.append(transform(row)) for row in list(zip(*nonogram))]
return dict([('rows', nrows), ('columns', ncolumns)]) == keys
......
----------------------------------------------------------------------
Ran 6 tests in 0.005s

OK
Петър Камбуров
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Камбуров
def validate_rows(nonogram, matrix):
row_count = 0
for row in nonogram:
if row.count('X') != sum(matrix[row_count]):
return False
row_count += 1
return True
def validate_nonogram(nonogram, keys):
transposed_matrix = [list(row) for row in zip(*nonogram)]
return (validate_rows(nonogram, keys['rows']) and
validate_rows(transposed_matrix, keys['columns']))
......
----------------------------------------------------------------------
Ran 6 tests in 0.003s

OK
Стефан Колчев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Колчев
def validate_nonogram(nonogram, keys):
for row, values in zip(nonogram, keys['rows']):
row_as_string = ''.join(row)
for value in values:
substring = 'X' * value
position = row_as_string.find(substring)
if position == -1:
return False
else:
position += len(substring)
if position == len(row_as_string):
continue
elif row_as_string[position] == ' ':
row_as_string = row_as_string[position:]
else:
return False
for col, values in zip(range(0, len(nonogram)), keys['columns']):
col_as_string = ''.join([row[col] for row in nonogram])
for value in values:
substr = 'X' * value
position = col_as_string.find(substr)
if position == -1:
return False
else:
position += len(substr)
if position == len(col_as_string):
continue
elif col_as_string[position] == ' ':
col_as_string = col_as_string[position:]
else:
return False
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.005s

OK
Димитър Трендафилов
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Трендафилов
from itertools import groupby
def validate_nonogram(nonogram, keys):
right_keys = {'rows': [], 'columns': []}
for row in nonogram:
if 'X' in row:
right_keys['rows'].append([sum(1 for _ in group) for key, group
in groupby(row) if key == 'X'])
else:
right_keys['rows'].append([0])
for column in zip(*nonogram):
if 'X' in column:
right_keys['columns'].append([sum(1 for _ in group) for key, group
in groupby(column) if key == 'X'])
else:
right_keys['columns'].append([0])
return right_keys['rows'] == keys['rows'] and right_keys[
'columns'] == keys['columns']
......
----------------------------------------------------------------------
Ran 6 tests in 0.005s

OK
Атанас Димитров
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Атанас Димитров
import re
def validate_nonogram(nonogram, keys):
return validator(nonogram, keys, 'rows') and \
validator(list(zip(*nonogram)), keys, 'columns')
def validator(nonogram, keys, keyword):
for index in range(len(keys[keyword])):
string = ''.join(nonogram[index])
pattern = r''
for number in keys[keyword][index]:
pattern += 'X'*number + ' *'
if not re.search(pattern, string):
return False
return True
..F...
======================================================================
FAIL: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-pms225/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 6 tests in 0.029s

FAILED (failures=1)
Деян Камбуров
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Камбуров
import re
def validate_nonogram(nonogram, keys):
return (is_nonogram(keys['rows'], (x for x in nonogram)) and
is_nonogram(keys['columns'], zip(*nonogram)))
def is_nonogram(keys, nonogram):
for row in keys:
match = re.search(create_pattern(row), ''.join(next(nonogram)))
if match is None:
return False
return True
def create_pattern(key):
pattern = '^[^X]*'
for number in key:
pattern += 'X' * number + '[^X]*'
return pattern + '$'
......
----------------------------------------------------------------------
Ran 6 tests in 0.035s

OK
Иван Иванов
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Иванов
def check_row(row, key):
if key == [0]:
for item in row:
if not item == ' ':
return False
return True
new_key = []
count = 0
for item in row:
if item == ' ':
if count:
new_key.append(count)
count = 0
else:
count += 1
if count:
new_key.append(count)
return new_key == key
def validate_nonogram(nonogram, keys):
for index, row in enumerate(nonogram):
if not check_row(row, keys['rows'][index]):
return False
nonogram = zip(*nonogram)
for index, row in enumerate(nonogram):
if not check_row(row, keys['columns'][index]):
return False
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.004s

OK
Димитър Желев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Желев
import re
def validate_nonogram(nonogram, keys):
"""validate if nonogram is a solution for keys"""
rows = [''.join(row) for row in nonogram]
row_patterns = ["^[' ']*" + ''.join(["[X]{" + str(item) + "}[' ']*"
for item in row]) + "$"
for row in keys['rows']]
for index, item in enumerate(rows):
match = re.search(row_patterns[index], item)
if match is None:
return False
columns = [''.join([row[index] for row in nonogram])
for index in range(len(nonogram))]
column_patterns = ["^[' ']*" + ''.join(["[X]{" + str(item) + "}[' ']*"
for item in column]) + "$"
for column in keys['columns']]
for index, item in enumerate(columns):
match = re.search(column_patterns[index], item)
if match is None:
return False
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.057s

OK
Божидар Михайлов
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Михайлов
from re import match
def validate_rows(nonogram, keys):
for key, line in zip(keys, nonogram):
pattern = '^ *' +\
''.join('X{' + str(count) + '} +' for count in key[:-1]) +\
'X{' + str(key[-1]) + '} *$'
if match(pattern, ''.join(line)) == None:
return False
return True
def validate_nonogram(nonogram, keys):
return (validate_rows(nonogram, keys['rows']) and
validate_rows(zip(*nonogram), keys['columns']))
......
----------------------------------------------------------------------
Ran 6 tests in 0.039s

OK
Таня Христова
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Таня Христова
import re
def validate_nonogram(nonogram, keys):
#validating rows
rows = get_rows(nonogram)
for i in range(len(keys['rows'])):
key = keys['rows'][i]
row = rows[i]
regex = re.compile(get_regex(key))
if not regex.match(row):
return False
#validating columns
columns = get_columns(nonogram)
for i in range(len(keys['columns'])):
key = keys['columns'][i]
column = columns[i]
regex = re.compile(get_regex(key))
if not regex.match(column):
return False
return True
def get_regex(keys):
regex = r' *'
for key in keys:
x = r'X' * key
if not key == keys[-1]:
regex += x + r' +'
else:
regex += x + r' *'
return regex
def get_rows(nonogram):
rows = []
for row in nonogram:
row_nonogram = ''.join(row)
rows.append(row_nonogram)
return rows
def get_columns(nonogram):
columns = []
for i in range(len(nonogram[0])):
column = []
for row in nonogram:
column.append(row[i])
col_nonogram = ''.join(column)
columns.append(col_nonogram)
return columns
..F...
======================================================================
FAIL: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-11nsykj/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 6 tests in 0.031s

FAILED (failures=1)
Мария Кърчева
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Кърчева
def transpose_nonogram(nonogram):
tranposed_nonogram = []
for i in range(len(nonogram[0])):
tranposed_nonogram.append([row[i] for row in nonogram])
return tranposed_nonogram
def make_row_value(nonogram):
rows = []
for row in nonogram:
count_x_in_row = 0
row_value = []
for el in row:
if el == 'X':
count_x_in_row += 1
elif count_x_in_row != 0:
row_value.append(count_x_in_row)
count_x_in_row = 0
if count_x_in_row != 0:
row_value.append(count_x_in_row)
elif row_value == []:
row_value.append(0)
rows.append(row_value)
return rows
def validate_nonogram(nonogram, keys):
return (make_row_value(nonogram) == keys['rows'] and
make_row_value(transpose_nonogram(nonogram)) == keys['columns'])
......
----------------------------------------------------------------------
Ran 6 tests in 0.004s

OK
Стоян Ефтимов
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Стоян Ефтимов
import re
def expected_key(element):
pattern = r'X+'
matches = re.findall(pattern, element)
if not matches:
return [0]
return [len(match) for match in matches]
def validate_nonogram(nonogram, keys):
rows = [''.join(row) for row in nonogram]
columns = [''.join(col) for col in list(zip(*nonogram))]
expected_keys = {'rows': [expected_key(row) for row in rows],
'columns': [expected_key(col) for col in columns]}
return expected_keys == keys
......
----------------------------------------------------------------------
Ran 6 tests in 0.012s

OK
Антония Чекръкчиева
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Антония Чекръкчиева
def validate_nonogram(nonogram, keys):
all_boxes = 0;
for i in range(len(nonogram)):
row_boxes = 0
for j in nonogram[i]:
if j == 'X':
row_boxes += 1
if row_boxes == sum(keys['rows'][i]):
all_boxes += 1
for i in range(len(nonogram)):
column_boxes = 0
for j in range(len(nonogram)):
if nonogram[j][i] == 'X':
column_boxes += 1
if column_boxes == sum(keys['columns'][i]):
all_boxes += 1
return all_boxes == len(nonogram) * 2
......
----------------------------------------------------------------------
Ran 6 tests in 0.004s

OK
Васил Тодоров
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Васил Тодоров
def get_keys_for_row(nonogram, row):
result = []
counter = 0
current_row = nonogram[row]
for i in range(0, len(current_row)):
if current_row[i] == 'X':
counter = counter + 1
elif counter > 0:
result.append(counter)
counter = 0
if counter > 0:
result.append(counter)
if result == []:
result.append(0)
return result
def get_keys_for_col(nonogram, col):
column = []
for row in range(0, len(nonogram)):
column.append(nonogram[row][col])
result = []
counter = 0
for i in range(0, len(column)):
if column[i] == 'X':
counter = counter + 1
elif counter > 0:
result.append(counter)
counter = 0
if counter > 0:
result.append(counter)
if result == []:
result.append(0)
return result
def validate_nonogram(nonogram, keys):
columns = []
rows = []
for i in range(0, len(nonogram)):
rows.append(get_keys_for_row(nonogram, i))
for i in range(0, len(nonogram[0])):
columns.append(get_keys_for_col(nonogram, i))
return keys['rows'] == rows and keys['columns'] == columns
......
----------------------------------------------------------------------
Ran 6 tests in 0.007s

OK
Дарина Кръстева
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Дарина Кръстева
import re
def generate_regular_expression(keys):
regular_expression = r" *"
for key in keys[:-1]:
regular_expression += r"X{}{}{} +".format('{', str(key), '}')
regular_expression += r"X{}{}{} *$".format('{', str(keys[-1]), '}')
return regular_expression
def validate_nonogram(nonogram, keys):
strings_by_rows = []
for row in nonogram:
row_string = ''.join(row)
strings_by_rows.append(row_string)
strings_by_columns = []
rows_and_columns_number = len(nonogram)
for column_index in range(0, rows_and_columns_number):
column_string = ''
for row_index in range(0, rows_and_columns_number):
column_string += nonogram[row_index][column_index]
strings_by_columns.append(column_string)
for index in range(0, rows_and_columns_number):
if re.match(generate_regular_expression(keys['rows'][index]),
strings_by_rows[index]) is None:
return False
if re.match(generate_regular_expression(keys['columns'][index]),
strings_by_columns[index]) is None:
return False
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.039s

OK
Венцислав Велков
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Венцислав Велков
from functools import reduce
import re
def validate_nonogram(nonogram, keys):
for index, row in enumerate(keys['rows']):
pattern = ''
for n in row:
pattern += "X{%s} +" % (str(n))
pattern = pattern[:-2]
if not re.search(pattern, reduce(str.__add__, nonogram[index])):
return False
for index, col in enumerate(keys['columns']):
pattern = ''
for n in col:
pattern += "X{%s} +" % (str(n))
pattern = pattern[:-2]
column = ''
for row in nonogram:
column += row[index]
if not re.search(pattern, column):
return False
return True
..F...
======================================================================
FAIL: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1d3auuw/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 6 tests in 0.036s

FAILED (failures=1)
Евгени Евлогиев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Евгени Евлогиев
import re
def create_expression(filled_fields):
expression = r''
for number in filled_fields:
expression = expression + 'X' * number + '\s*'
return expression
def get_column(nonogram, index):
return ''.join(nonogram[i][index] for i in range(len(nonogram)))
def validate_nonogram(nonogram, keys):
for i in range(len(keys['rows'])):
string = ''.join(i for i in nonogram[i])
match = re.search(create_expression(keys['rows'][i]), string)
if not match:
return False
start, end = match.span()
if 'X' in string[end:]:
return False
for i in range(len(keys['columns'])):
string = get_column(nonogram, i)
match = re.search(create_expression(keys['columns'][i]), string)
if not match:
return False
start, end = match.span()
if 'X' in string[end:]:
return False
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.036s

OK
Теодор Халваджиев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Халваджиев
import re
def check_correctness(nonogram, conditions):
for index, group in enumerate(conditions):
concatenated = "".join(nonogram[index])
pattern = ("\s*" + "X{{{}}}\s*" * len(group) + "$").format(*group)
if(not bool(re.match(pattern, concatenated))):
return False
return True
def validate_nonogram(nonogram, keys):
return check_correctness(nonogram, keys['rows']) and \
check_correctness(list(zip(*nonogram)), keys['columns'])
......
----------------------------------------------------------------------
Ran 6 tests in 0.041s

OK
Николай Масларски
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Масларски
def validate_row(key, row):
index = len(row) - 1
for x in reversed(key):
i = 0
while row[index] == ' ' and index >= 0:
index -= 1
while row[index] == 'X' and index >= 0:
index -= 1
i += 1
if i != x:
return False
return True
def validate_nonogram(nonogram, keys):
flag = True
for (key, rows) in zip(keys['rows'], nonogram):
flag *= validate_row(key, rows)
for i in range(len(keys['columns'])):
flag *= validate_row(keys['columns'][i],
[x[i] for x in nonogram])
return bool(flag)
......
----------------------------------------------------------------------
Ran 6 tests in 0.005s

OK
Снежана Спасова
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Снежана Спасова
import re
def check(nonogram, keys, rows):
for index, row in enumerate(keys[rows]):
filtered = [re.search('[X]{' + str(x) + '}',
''.join(nonogram[index])) for x in row]
if not row == [len(x.group()) for x in filtered if x != None]:
return False
return True
def validate_nonogram(nonogram, keys):
return check(nonogram, keys, 'rows') and check(reverse(nonogram), keys, 'columns')
def reverse(nonogram):
return [list(i) for i in zip(*nonogram)]
..F...
======================================================================
FAIL: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-15uj2kg/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 6 tests in 0.025s

FAILED (failures=1)
Валентин Петров
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Валентин Петров
import re
def chk_helper(nonogram, keys):
for key,row in zip(keys,nonogram):
start = 0
end = 0
for i in key:
regex = r'\bX{%s}\b' % i
result = re.search(regex,''.join(row[end:]))
if not result:
return False
start, end = result.span()
return True
def validate_nonogram(nonogram, keys):
return chk_helper(nonogram,keys['rows']) and chk_helper(zip(*(nonogram)),keys['columns'])
......
----------------------------------------------------------------------
Ran 6 tests in 0.022s

OK
Атанас Пройчев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Пройчев
from re import findall
def validate_nonogram(nonogram, keys):
return validate(nonogram, keys['rows']) and \
validate(zip(*nonogram), keys['columns'])
def validate(matrix, rows):
for index, row in enumerate(matrix):
list_of_X = findall(r'X+', ''.join(row))
for num, value in enumerate(rows[index]):
if value == 0:
if len(list_of_X) > 0:
return False
else:
continue
if value != len(list_of_X[num]):
return False
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.008s

OK
Спасимир Тупаров
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Спасимир Тупаров
import re
def check_sentence(number_filled, sentence):
to_be_checked = sentence.split(" ")
found = False
for n_times in number_filled:
for to_pop, element in enumerate(to_be_checked):
if "X"*n_times == element:
to_be_checked.pop(to_pop)
found = True
break
if found is False:
return False
to_be_checked = "".join(to_be_checked)
return bool(not(re.search(r'X+', to_be_checked)))
def validate_rows(key_rows, nonogram):
for row_number, number_filled_elements in enumerate(key_rows):
sentence = "".join(nonogram[row_number])
if not (check_sentence(number_filled_elements, sentence)):
return False
return True
def validate_columns(keys_columns, nonogram):
size = len(nonogram)
for column_number, number_filled_elements in enumerate(keys_columns):
row = 0
sentence = ""
while row < size:
sentence += nonogram[row][column_number]
row += 1
if not (check_sentence(number_filled_elements, sentence)):
return False
return True
def validate_nonogram(nonogram, keys):
return validate_rows(keys['rows'], nonogram) and validate_columns(keys['columns'], nonogram)
......
----------------------------------------------------------------------
Ran 6 tests in 0.011s

OK
Милица Борисова
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Милица Борисова
import itertools
import re
def transpose(matrix):
return [list(vector) for vector in zip(*matrix)]
def check_one_line(string, number):
if number == 0:
return bool(re.search(r'\s{%d}' % len(string),string))
return bool(re.search(r'\bX{%d}\b' % number, string)) or\
bool(re.search(r'\bX{%d}$' % number, string)) or\
bool(re.match(r'X{%d}\b' % number, string))
def check_one_matrix(matrix, solutions):
for i in range(len(solutions)):
for solution in solutions[i]:
if not check_one_line(''.join(matrix[i]), solution) or\
not sum(solutions[i]) == matrix[i].count('X'):
return False
return True
def validate_nonogram(nonogram, keys):
return check_one_matrix(nonogram,keys['rows']) and\
check_one_matrix(transpose(nonogram),keys['columns'])
......
----------------------------------------------------------------------
Ran 6 tests in 0.027s

OK
Денис Бялев
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Денис Бялев
def validate_nonogram(nonogram, keys):
for i in nonogram:
if sum(keys['rows'][nonogram.index(i)]) != i.count('X'):
return False
return True
F.....
======================================================================
FAIL: test_error_in_columns (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-edc70f/test.py", line 41, in test_error_in_columns
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 6 tests in 0.004s

FAILED (failures=1)
Даяна Маринова
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Даяна Маринова
import re
def generate_pattern(array):
pattern = ''
for it in array:
pattern += '.*(X){%s}' % it
return pattern
def matrix_transposition(nonogram):
new_nonogram = [[j[i] for j in nonogram] for i in range(len(nonogram))]
return new_nonogram
def if_match(array, nonogram):
string = ''
for index in range(0, len(nonogram)):
string = ''.join(nonogram[index])
value = array[index]
m = re.match(generate_pattern(value), string)
if m is None:
return False
return True
def validate_nonogram(nonogram, keys):
rows_value = keys['rows']
columns_value = keys['columns']
if if_match(rows_value, nonogram) and if_match(columns_value, matrix_transposition(nonogram)):
return True
return False
..F...
======================================================================
FAIL: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1dtlh5f/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 6 tests in 0.053s

FAILED (failures=1)
Елена Димитрова
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Елена Димитрова
def is_valid(groups, row):
index = 0
current_group_length = groups[0]
at_group = 0
group_length = 0
while index < len(row):
if group_length == current_group_length and row[index] == 'X':
return False
if at_group == len(groups) and row[index] != ' ':
return False
if row[index] == ' ' and group_length != 0:
if group_length == current_group_length:
at_group += 1
if (at_group < len(groups)):
current_group_length = groups[at_group]
group_length = 0
else:
return False
elif row[index] == 'X':
group_length += 1
index += 1
if group_length == current_group_length:
at_group += 1
if at_group < len(groups):
return False
return True
def get_column(nanogram, column_index):
column = []
index = 0
while index < len(nanogram):
column.append(nanogram[index][column_index])
index += 1
return column
def validate_nonogram(nonogram, keys):
row_keys = keys['rows']
for row_key in row_keys:
index = row_keys.index(row_key)
if not is_valid(row_key, nonogram[index]):
return False
column_keys = keys['columns']
for column_key in column_keys:
index = column_keys.index(column_key)
if not is_valid(column_key, get_column(nonogram, index)):
return False
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.009s

OK
Ангел Цанев
  • Некоректно
  • 0 успешни тест(а)
  • 6 неуспешни тест(а)
Ангел Цанев
import itertools
def transpose_nonogram(nonogram):
return [list(x) for x in zip(*nonogram)]
def filter_key(x):
return x[0]=='X'
def get_sequence(line):
sequence = filter(filter_key, [list(group) for key, group in groupby(line)])
return list(map(lambda x: len(x), sequence))
def validate_nonogram(nonogram, keys):
transposed_nonogram = transpose_nonogram(nonogram)
for line in range(0, len(nonogram)):
if keys['rows'][line] != get_sequence(nonogram[line]):
return False
if keys['columns'][line] != get_sequence(transposed_nonogram[line]):
return False
return True
EEEEEE
======================================================================
ERROR: test_error_in_columns (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1jm7co/test.py", line 41, in test_error_in_columns
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-1jm7co/solution.py", line 16, in validate_nonogram
    if  keys['rows'][line] != get_sequence(nonogram[line]):
  File "/tmp/d20140423-11348-1jm7co/solution.py", line 10, in get_sequence
    sequence = filter(filter_key, [list(group) for key, group in groupby(line)])
NameError: global name 'groupby' is not defined

======================================================================
ERROR: test_error_in_rows (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1jm7co/test.py", line 29, in test_error_in_rows
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-1jm7co/solution.py", line 16, in validate_nonogram
    if  keys['rows'][line] != get_sequence(nonogram[line]):
  File "/tmp/d20140423-11348-1jm7co/solution.py", line 10, in get_sequence
    sequence = filter(filter_key, [list(group) for key, group in groupby(line)])
NameError: global name 'groupby' is not defined

======================================================================
ERROR: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1jm7co/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-1jm7co/solution.py", line 16, in validate_nonogram
    if  keys['rows'][line] != get_sequence(nonogram[line]):
  File "/tmp/d20140423-11348-1jm7co/solution.py", line 10, in get_sequence
    sequence = filter(filter_key, [list(group) for key, group in groupby(line)])
NameError: global name 'groupby' is not defined

======================================================================
ERROR: test_python_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1jm7co/test.py", line 165, in test_python_nonogram
    python_keys))
  File "/tmp/d20140423-11348-1jm7co/solution.py", line 16, in validate_nonogram
    if  keys['rows'][line] != get_sequence(nonogram[line]):
  File "/tmp/d20140423-11348-1jm7co/solution.py", line 10, in get_sequence
    sequence = filter(filter_key, [list(group) for key, group in groupby(line)])
NameError: global name 'groupby' is not defined

======================================================================
ERROR: test_ruby_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1jm7co/test.py", line 285, in test_ruby_nonogram
    self.assertTrue(solution.validate_nonogram(ruby_nonogram, ruby_keys))
  File "/tmp/d20140423-11348-1jm7co/solution.py", line 16, in validate_nonogram
    if  keys['rows'][line] != get_sequence(nonogram[line]):
  File "/tmp/d20140423-11348-1jm7co/solution.py", line 10, in get_sequence
    sequence = filter(filter_key, [list(group) for key, group in groupby(line)])
NameError: global name 'groupby' is not defined

======================================================================
ERROR: test_valid_nonogram (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1jm7co/test.py", line 17, in test_valid_nonogram
    self.assertTrue(solution.validate_nonogram(nonogram, keys))
  File "/tmp/d20140423-11348-1jm7co/solution.py", line 16, in validate_nonogram
    if  keys['rows'][line] != get_sequence(nonogram[line]):
  File "/tmp/d20140423-11348-1jm7co/solution.py", line 10, in get_sequence
    sequence = filter(filter_key, [list(group) for key, group in groupby(line)])
NameError: global name 'groupby' is not defined

----------------------------------------------------------------------
Ran 6 tests in 0.006s

FAILED (errors=6)
Стоян Христов
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Стоян Христов
def validate(nonogram, rows_or_columns):
for index in range(len(rows_or_columns)):
row_or_column = [
len(word) for word in ''.join(nonogram[index]).split()]
if row_or_column == []:
row_or_column.append(0)
if rows_or_columns[index] != row_or_column:
return False
return True
def validate_nonogram(nonogram, keys):
return validate(nonogram, keys['rows']) and\
validate(list(zip(*nonogram)), keys['columns'])
......
----------------------------------------------------------------------
Ran 6 tests in 0.005s

OK
Кирил Киров
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Кирил Киров
import re
def spaceTOa(line_from_nonogram):
string_with_a = []
for letter in line_from_nonogram:
if letter == ' ':
string_with_a.append('a')
else:
string_with_a.append(letter.lower())
return string_with_a
def nonogram_to_row(nonograma):
nonogram_in_string = []
for line in nonograma:
line_to_a = spaceTOa(line)
temp = ''.join(line_to_a)
nonogram_in_string.append(temp.lower())
return nonogram_in_string
def nonogram_to_col(nonograma):
len_line = len(nonograma[0])
i = 0
col_list = []
while i < len_line:
temp = []
for no in nonograma:
temp.append(no[i])
temp = spaceTOa(temp)
tem = ''.join(temp)
i = i + 1
col_list.append(tem.lower())
return col_list
# ako imam [1,2] ->a+xa*xxa*
def list_to_reg(instructions):
result = ['a*']
for number in instructions:
regular_expression = 'x{' + \
str(number) + ',' + str(number) + '}' + 'a+'
result.append(regular_expression)
last_elememnt = result[len(result) - 1]
result.pop(len(result) - 1)
result.append(last_elememnt[:-1] + '*')
return ''.join(result).lower()
def validate_nonogram(nonogram, keys):
nonogram_to_columns = nonogram_to_col(nonogram)
nonogram_to_rows = nonogram_to_row(nonogram)
regular_exp_rows = [list_to_reg(i) for i in keys['rows']]
regular_exp_cols = [list_to_reg(i) for i in keys['columns']]
if (len(nonogram_to_columns) != len(regular_exp_cols)):
return False
if (len(nonogram_to_rows) != len(regular_exp_rows)):
return False
i = 0
while i < len(nonogram_to_columns):
if type(re.match(regular_exp_cols[i], nonogram_to_columns[i])) == type(None):
return False
i = i + 1
i = 0
while i < len(nonogram_to_rows):
if type(re.match(regular_exp_rows[i], nonogram_to_rows[i])) == type(None):
return False
i = 1 + i
return True
..F...
======================================================================
FAIL: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1kd2w28/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 6 tests in 0.042s

FAILED (failures=1)
Данаил Койчев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Данаил Койчев
import re
def validate_lines(lines, keys):
for index, line in enumerate(lines):
line = "".join(line)
regex = '\\s*'
for symbol in keys[index]:
regex += 'X{{{0}}}\\s*'.format(symbol)
regex += '$'
if re.match(regex, line) is None:
return False
return True
def validate_nonogram(nonogram, keys):
columns = [[row[i] for row in nonogram] for i in range(len(nonogram[0]))]
return validate_lines(nonogram, keys['rows']) and \
validate_lines(columns, keys['columns'])
......
----------------------------------------------------------------------
Ran 6 tests in 0.050s

OK
Радослав Георгиев
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Радослав Георгиев
def chopped(iterable, separator):
chunk = []
for elem in iterable:
if not elem == separator:
chunk.append(elem)
elif chunk:
yield chunk
chunk = []
if chunk:
yield chunk
def key(item):
return [chunk.count('X') for chunk in chopped(item, ' ')]
def validate_nonogram(nonogram, keys):
return keys['rows'] == [key(row) for row in nonogram] and keys['columns'] == [key(col) for col in zip(*nonogram)]
......
----------------------------------------------------------------------
Ran 6 tests in 0.005s

OK
Лъчезар Николов
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Лъчезар Николов
def validate_nonogram(nonogram, keys):
rows_sum = sum_groups(nonogram)
transposed = transpose(nonogram)
columns_sum = sum_groups(transposed)
return rows_sum == keys['rows'] and columns_sum == keys['columns']
def transpose(matrix):
return list(map(list, zip(*matrix)))
def sum_groups(nonogram):
groups_sum = []
for row in nonogram:
current_row_groups = []
current_group = 0
for cell in row:
if cell == 'X':
current_group += 1
else:
current_row_groups.append(current_group)
current_group = 0
current_row_groups.append(current_group)
current_row_groups = list(filter(lambda x: x != 0, current_row_groups))
if not current_row_groups:
current_row_groups.append(0)
groups_sum.append(current_row_groups)
return groups_sum
......
----------------------------------------------------------------------
Ran 6 tests in 0.006s

OK
Любомир Коев
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Любомир Коев
from re import match
def validate_nonogram(nonogram, keys):
def regex_from_ar(ar):
return ' *' + ''.join(['X{{{}}}'.format(val) + ' *' for val in ar])
def match_check(check, data):
return all(map(lambda pair: match(pair[0], pair[1]), zip(check, data)))
row_check = [regex_from_ar(row) for row in keys['rows']]
col_check = [regex_from_ar(col) for col in keys['columns']]
rows = [''.join(row) for row in nonogram]
cols = [''.join([nonogram[row][col] for row in range(0, len(nonogram))])
for col in range(0, len(nonogram[0]))]
return match_check(row_check, rows) and match_check(col_check, cols)
..F...
======================================================================
FAIL: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1mir0z3/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 6 tests in 0.038s

FAILED (failures=1)
Пламен Димитров
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Пламен Димитров
def transposition(nonogram, keys):
lines = []
target_symbol = 0
for nonogram_row in nonogram:
current_range = []
whisper = True
for index in nonogram_row:
if index == 'X':
whisper = False
target_symbol += 1
continue
else:
if target_symbol != 0:
current_range.append(target_symbol)
target_symbol = 0
if target_symbol != 0:
current_range.append(target_symbol)
lines.append(current_range)
target_symbol = 0
else:
if whisper:
current_range.append(0)
lines.append(current_range)
return keys == lines
def validate_nonogram(nonogram, keys):
return transposition(nonogram, keys['rows']) and\
transposition(list(zip(*nonogram)), keys['columns'])
......
----------------------------------------------------------------------
Ran 6 tests in 0.005s

OK
Виктор Иванов
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Виктор Иванов
import re
def check(nonogram, keys):
for key, row in zip(keys, nonogram):
regex = " *"
for count in key:
regex += 'X{''' + str(count) + '} +'
regex += '$'
if not re.match(regex, ''.join(row) + ' '):
return False
return True
def validate_nonogram(nonogram, keys):
transposed = [list(column) for column in zip(*nonogram)]
return check(nonogram, keys['rows']) and check(transposed, keys['columns'])
......
----------------------------------------------------------------------
Ran 6 tests in 0.049s

OK
Теодора Добрева
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Теодора Добрева
def validate(nonogram):
generated_keys = []
for index, row in enumerate(nonogram):
filled_cells_count = 0
generated_keys.append([])
for cell in row:
if cell == ' ' and filled_cells_count > 0:
generated_keys[index].append(filled_cells_count)
filled_cells_count = 0
elif cell == 'X':
filled_cells_count += 1
if generated_keys[index] == [[]]:
generated_keys[index].append(0)
if filled_cells_count > 0:
generated_keys[index].append(filled_cells_count)
return generated_keys
def validate_nonogram(nonogram, keys):
keys_from_nonogram = {}
keys_from_nonogram['rows'] = validate(nonogram)
nonogram = [list(item) for item in zip(*nonogram)]
keys_from_nonogram['columns'] = validate(nonogram)
return keys_from_nonogram == keys
......
----------------------------------------------------------------------
Ran 6 tests in 0.006s

OK
Стефан Владков
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Владков
import re
def validate_nonogram(nonogram, keys):
transposed = transpose(nonogram)
isNonogram = validate(nonogram, keys['rows'])
return isNonogram and validate(transposed, keys['columns'])
def transpose(matrix):
transposed = [list(i) for i in zip(*matrix)]
return transposed
def validate(nonogram, key):
counter = 0
for row in nonogram:
row_as_string = ''.join(row)
current_key = key[counter]
expression = ''
if current_key[0] == 0:
expression = '\s{' + str(len(row)) + '}'
else:
for repetition in current_key:
expression += "\s+X{" + str(repetition) + '}'
expression = '' + expression[3:]
result = re.findall(str(expression), row_as_string)
if len(result) != 1:
return False
counter += 1
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.036s

OK
Ивайло Бъчваров
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Ивайло Бъчваров
import re
def construct_pattern(key):
zero_or_one = "\s*"
one_or_more = "\s+"
pattern = zero_or_one
for number in key:
pattern += "X{%s}%s" % (number, one_or_more)
# It may not finish with one_or_more spaces, so remove it and place zero_or_more
pattern = pattern[:-3]
pattern += zero_or_one
return(pattern)
def check_rows(nanogram, requirement, key):
for (matrix_row, key_row) in zip(nanogram, requirement[key]):
pattern = construct_pattern(key_row)
row = "".join(matrix_row)
match = re.match(pattern, row)
if not match:
return False
return True
def validate_nonogram(nonogram, requirement):
transponed = [list(i) for i in zip(*nonogram)]
rows_valid = check_rows(nonogram, requirement, "rows")
cols_valid = check_rows(transponed, requirement, "columns")
return rows_valid and cols_valid
..F...
======================================================================
FAIL: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1tkgwx1/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 6 tests in 0.052s

FAILED (failures=1)
Весела Бандова
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Весела Бандова
import re
def validate_nonogram(nonogram, keys):
rows = keys["rows"]
cols = keys["columns"]
for row in range(len(nonogram)):
pattern = "^ *" + " +".join(["X"*j for j in rows[row]]) + " *$"
strg = "".join(nonogram[row])
if re.match(pattern, strg) is None:
return False
for i in range(len(nonogram[0])):
pattern = "^ *" + " +".join(["X"*j for j in cols[i]]) + " *$"
strg = "".join([nonogram[j][i] for j in range(len(nonogram))])
if re.match(pattern, strg) is None:
return False
return True
......
----------------------------------------------------------------------
Ran 6 tests in 0.041s

OK
Моника Димитрова
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Моника Димитрова
import re
def validate_nonogram(nonogram, keys):
for row in nonogram:
row_occurences = keys['rows'][nonogram.index(row)]
row_pattern = generate_pattern(row_occurences)
if not row_pattern.search("".join(row)):
return False
transposed = [list(i) for i in zip(*nonogram)]
for column in transposed:
column_occurences = keys['columns'][transposed.index(column)]
column_pattern = generate_pattern(column_occurences)
if not column_pattern.search("".join(column)):
return False
return True
def generate_pattern(occurences):
pattern = ''
for occurence in occurences:
pattern += 'X{%d}( +|$)' % occurence
return re.compile(pattern)
..F...
======================================================================
FAIL: test_mandatory_empty_square_between_groups (test.TestValidateNonogram)
----------------------------------------------------------------------
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/d20140423-11348-1b0sc40/test.py", line 50, in test_mandatory_empty_square_between_groups
    self.assertFalse(solution.validate_nonogram(nonogram, keys))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 6 tests in 0.053s

FAILED (failures=1)