Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Nonogram Encode by Oleg_Levonjuk
def nonogram_encode(data: list[str]) -> list[list[list[int]]]:
data_transposed = [''.join([data[c][r] for c in range(len(data))]) for r in range(len(data[0]))]
column_count = [[len(x) for x in r.split(' ') if len(x)] for r in data_transposed]
row_count = [[len(x) for x in r.split(' ') if len(x)] for r in data]
column_clue = [list(r) for r in zip(*[([0]*(max([len(n) for n in column_count])-len(c)) + c) for c in column_count])]
row_clue = [([0]*(max([len(n) for n in row_count])-len(r)) + r) for r in row_count]
return [column_clue, row_clue]
print("Example:")
print(nonogram_encode([" X X ", "X X X", " X X "]))
# These "asserts" are used for self-checking
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!")
Jan. 7, 2023
Comments: