Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Nonogram Encode by freeman_lex
def nonogram_encode(data):
def calc(ar):
nums = [[len(i) for i in row.split(' ') if i] for row in ar]
max_nums = max(map(len, nums))
nums = [[0] * (max_nums - len(i)) + i for i in nums]
return nums
trans = [''.join(row[i] for row in data) for i in range(len(data[0]))]
hor = calc(data)
ver = calc(trans)
ver = [[row[i] for row in ver] for i in range(len(ver[0]))]
return [ver, hor]
print("Example:")
print(nonogram_encode([" X X ", "X X X", " X X "]))
assert nonogram_encode([" X X ", "X X X", " X X "]) == [
[[0, 1, 0, 1, 0], [1, 1, 1, 1, 1]],
[[0, 1, 1], [1, 1, 1], [0, 1, 1]],
]
assert nonogram_encode(["X"]) == [[[1]], [[1]]]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Aug. 25, 2022