写一个python的数字华容道 要求有解
时间: 2023-03-13 08:52:28 浏览: 149
我可以为你提供一个python代码实现的数字华容道:def solve_HRD(board):
row_size = len(board)
column_size = len(board[0])
step = 0
while step < row_size + column_size - 1:
for i in range(row_size):
for j in range(column_size):
if board[i][j] == (step % row_size):
if i == 0 or board[i-1][j] == -1:
board[i][j] = -1
step += 1
break
else:
board[i][j], board[i-1][j] = board[i-1][j], board[i][j]
step += 1
break
for j in range(column_size):
for i in range(row_size):
if board[i][j] == (step % row_size):
if j == 0 or board[i][j-1] == -1:
board[i][j] = -1
step += 1
break
else:
board[i][j], board[i][j-1] = board[i][j-1], board[i][j]
step += 1
break
return board print(solve_HRD([[4,2,3],[1,6,5]]))
阅读全文