Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First - list return solution in Clear category for Matrix "Hatching" by freeman_lex
def hatching(matrix: list[list[int]]) -> list[list[int]]:
length, width = len(matrix), len(matrix[0])
strokes = [[] for _ in range(length+width-1)]
for col in range(width):
for row in range(length):
strokes[row + col].append(matrix[row][col])
return strokes
print("Example:")
print(list(hatching([[1, 2], [3, 4]])))
# These "asserts" are used for self-checking
assert list(hatching([[0]])) == [[0]]
assert list(hatching([[1, 2], [3, 4]])) == [[1], [3, 2], [4]]
assert list(hatching([[1, 2, 3, 4, 5], [6, 7, 8, 9, 0]])) == [
[1],
[6, 2],
[7, 3],
[8, 4],
[9, 5],
[0],
]
assert list(hatching([[1, 2], [3, 4], [5, 6], [7, 8], [9, 0]])) == [
[1],
[3, 2],
[5, 4],
[7, 6],
[9, 8],
[0],
]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Nov. 30, 2022