print_moves (344)

# 603xxxxx21 352 (2020-09-20 23:33) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 603xxxxx21 353 (2020-09-20 23:05) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 603xxxxx21 354 (2020-09-20 16:54) def print_moves(board, moves): # bonus function: optional look = [str(i) for i in board] title = len(look) dim = int(title**0.5) look = [look[i:i+dim] for i in range(0,title,dim)] print("\n".join([" ".join(i) for i in look])) zero_position = board.index(0) for direction in moves: print((dim**2)*'-'+" "+direction) if direction == 'U': board[zero_position],board[zero_position -dim] = board[zero_position -dim],board[zero_position] zero_position -= dim elif direction == 'D': board[zero_position],board[zero_position +dim] = board[zero_position +dim],board[zero_position] zero_position += dim elif direction == 'L': board[zero_position],board[zero_position -1] = board[zero_position -1],board[zero_position] zero_position -= 1 elif direction == 'R': board[zero_position],board[zero_position +1] = board[zero_position +1],board[zero_position] zero_position += 1 look = [str(i) for i in board] look = [look[i:i+dim] for i in range(0,title,dim)] print("\n".join([" ".join(i) for i in look])) return #------------------------------------------
# 603xxxxx21 355 (2020-09-20 18:13) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 603xxxxx21 356 (2020-09-20 23:12) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 603xxxxx21 357 (2020-09-20 20:06) def print_moves(board, moves): # bonus function: optional l = list(board) print(" "+ str(l[0]) + " " + str(l[1]) + " " + str(l[2])) print(" "+ str(l[3]) + " " + str(l[4]) + " " + str(l[5])) print(" "+ str(l[6]) + " " + str(l[7]) + " " + str(l[8])) for e in moves : if e == "D": print("--------- D") zero_pos = l.index(0) l[zero_pos] , l[zero_pos + 3 ] = l[zero_pos + 3 ] , l[zero_pos] print(" "+ str(l[0]) + " " + str(l[1]) + " " + str(l[2])) print(" "+ str(l[3]) + " " + str(l[4]) + " " + str(l[5])) print(" "+ str(l[6]) + " " + str(l[7]) + " " + str(l[8])) if e == "U": print("--------- U") zero_pos = l.index(0) l[zero_pos] , l[zero_pos - 3 ] = l[zero_pos - 3 ] , l[zero_pos] print(" "+ str(l[0]) + " " + str(l[1]) + " " + str(l[2])) print(" "+ str(l[3]) + " " + str(l[4]) + " " + str(l[5])) print(" "+ str(l[6]) + " " + str(l[7]) + " " + str(l[8])) if e == "L" : print("--------- L") zero_pos = l.index(0) l[zero_pos] , l[zero_pos - 1 ] = l[zero_pos - 1 ] , l[zero_pos] print(" "+ str(l[0]) + " " + str(l[1]) + " " + str(l[2])) print(" "+ str(l[3]) + " " + str(l[4]) + " " + str(l[5])) print(" "+ str(l[6]) + " " + str(l[7]) + " " + str(l[8])) if e == "R": print("--------- R") zero_pos = l.index(0) l[zero_pos] , l[zero_pos + 1 ] = l[zero_pos + 1 ] , l[zero_pos] print(" "+ str(l[0]) + " " + str(l[1]) + " " + str(l[2])) print(" "+ str(l[3]) + " " + str(l[4]) + " " + str(l[5])) print(" "+ str(l[6]) + " " + str(l[7]) + " " + str(l[8])) return #------------------------------------------
# 604xxxxx28 358 (2020-09-18 13:11) def print_moves(board, moves): print_board(board) for m in moves: print('-' * 9, m) do_move(m, board, board_is_node=False) print_board(board) return #------------------------------------------ def do_move(move: str, board: list, board_is_node: bool=True) -> bool: global board_size, board_items move = move.lower() if move not in "udlr": return False if not can_move(move, board): return False source_index = board.index(0) dest_index = None if move == 'u': dest_index = source_index - board_size elif move == 'd': dest_index = source_index + board_size elif move == 'l': dest_index = source_index - 1 elif move == 'r': dest_index = source_index + 1 try: board[source_index], board[dest_index] = board[dest_index], board[source_index] if board_is_node: board[-1] += move.upper() return True except IndexError: pass return False # Exact unmodified functions given in sample code are below def can_move(move: str, board: list) -> bool: global board_size, board_items move = move.lower() index = board.index(0) if move == 'u': return index - board_size >= 0 if move == 'd': return index + board_size < board_items if move == 'l': return (index % board_size) - 1 >= 0 if move == 'r': return (index % board_size) + 1 < board_size return False def print_board(board: list) -> None: global board_size format_str = ' ' + ' '.join(["{:<2}"] * board_size) line_start = 0 for line in range(board_size): line_end = (line + 1) * board_size print(format_str.format(*board[line_start:line_end])) line_start = line_end
# 614xxxxx28 359 (2020-09-20 21:16) def print_moves (board, moves): # bonus function: optional return # ------------------------------------------
# 623xxxxx21 360 (2020-09-20 21:37) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 361 (2020-09-20 19:06) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 362 (2020-09-17 22:49) def print_moves(board, moves): # bonus function: optional N = int(len(board)**(1/2)) #บอร์ดแรกก่อนสลับ for i in range(N): line = board[i*N:N*(i+1):] line_s = '' for e in line : line_s = line_s + str(e) + " " print(line_s) #ปริ้นmove b = board[:] for ch in moves : v = b.index(0) print('---------',ch) if ch == "U" : b[v],b[v-N] = b[v-N],b[v] if ch == "D" : b[v],b[v+N] = b[v+N],b[v] if ch == "L" : b[v],b[v-1] = b[v-1],b[v] if ch == "R" : b[v],b[v+1] = b[v+1],b[v] for i in range(N): line = b[i*N:N*(i+1):] line_s = '' for e in line : line_s = line_s + str(e) + " " print(line_s) return '' #------------------------------------------
# 623xxxxx21 363 (2020-09-20 23:38) def print_moves(board, moves): # bonus function: optional y=board for k in range(len(moves)): for i in range(0,9,3): print(str(y[i])+" "+str(y[i+1])+" "+str(y[i+2])) print("----------"+moves[k]) x=y.index(0,0) if moves[k]=='L': y[x],y[x-1]=y[x-1],y[x] if moves[k]=='R': y[x],y[x+1]=y[x+1],y[x] if moves[k]=='U': y[x],y[x-3]=y[x-3],y[x] if moves[k]=='D': y[x],y[x+3]=y[x+3],y[x] for i in range(0,9,3): print(str(y[i])+" "+str(y[i+1])+" "+str(y[i+2])) return #------------------------------------------
# 623xxxxx21 364 (2020-09-19 16:52) def print_moves(board, moves): board1=list(board) ans=[] com="" for i in range(len(moves)) : p=board.index(0) if moves[i] == "U" : U=list(board) U[p],U[p-3]=U[p-3],U[p] ans.append(U) board=list(U) elif moves[i] == "D" : D=list(board) D[p],D[p+3]=D[p+3],D[p] ans.append(D) board=list(D) elif moves[i] == "L" : L=list(board) L[p],L[p-1]=L[p-1],L[p] ans.append(L) board=list(L) elif moves[i] == "R" : R=list(board) R[p],R[p+1]=R[p+1],R[p] ans.append(R) board=list(R) com+=moves[i] for i in range(0,9,3) : print(" "+str(board1[i])+" "+str(board1[i+1])+" "+str(board1[i+2])) for i in range(len(ans)) : print("-"*9+" "+com[i]) for e in range(0,9,3) : print(" "+str(ans[i][e])+" "+str(ans[i][e+1])+" "+str(ans[i][e+2])) return #------------------------------------------
# 623xxxxx21 365 (2020-09-20 15:10) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 366 (2020-09-19 20:22) def print_moves(board, moves): # bonus function: optional return #-------------------------------------------
# 623xxxxx21 367 (2020-09-17 17:32) def print_moves(board, moves): # bonus function: optional l = int((len(board))**0.5) for i in range(l): f = board[i*l:i*l+l] p = "" for i in range(l): p += str(f[i]) + " " print(p[:-2]) for move in moves: print("---------", move) pos = board.index(0) if move == "U": board[pos], board[pos-l] = board[pos-l], board[pos] elif move == "D": board[pos], board[pos+l] = board[pos+l], board[pos] elif move == "L": board[pos], board[pos-1] = board[pos-1], board[pos] elif move == "R": board[pos], board[pos+1] = board[pos+1], board[pos] for i in range(l): f = board[i*l:i*l+l] p = "" for i in range(l): p += str(f[i]) + " " print(p[:-2]) return #------------------------------------------
# 623xxxxx21 368 (2020-09-20 23:40) def print_moves(board, moves): N = int(len(board)**0.5) for i in range(0,N**2,N): k = i+N-1 while i<k: print(board[i],end=' ') i += 1 print(board[i]) print(N**2*'-'+'1') #------------------------------------------
# 623xxxxx21 369 (2020-09-20 14:33) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 370 (2020-09-20 23:04) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 371 (2020-09-20 21:19) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 372 (2020-09-20 17:29) def print_moves(board, moves): # bonus function: optional for c in moves : print_board(board) pos = board.index(0) print("-----------------"+c) if (c=="D") : board[pos],board[pos+3] = board[pos+3],board[pos] if (c=="R") : board[pos],board[pos+1] = board[pos+1],board[pos] if (c=="U") : board[pos],board[pos-3] = board[pos-3],board[pos] if (c=="L") : board[pos],board[pos-1] = board[pos-1],board[pos] print_board(board) return #------------------------------------------ #board = [4,1,3,2,5,6,7,8,0] def print_board(board) : print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) #------------------------------------------
# 623xxxxx21 373 (2020-09-19 23:44) def print_moves(board, moves): # bonus function: optional n = int(len(board)**0.5) #print for i in range(n): out = "" for j in range(n): out += str(board[i*n+j]) + " " print(out) for x in range(len(moves)): index = board.index(0) if moves[x] == 'U': num = board[index-n] board[index] = num board[index-n] = 0 elif moves[x] == 'D': num = board[index+n] board[index] = num board[index+n] = 0 elif moves[x] == 'L': num = board[index-1] board[index] = num board[index-1] = 0 else: num = board[index+1] board[index] = num board[index+1] = 0 print("-"*(3*n) + " " + moves[x]) for i in range(n): out = "" for j in range(n): out += str(board[i*n+j]) + " " print(out) return #------------------------------------------
# 623xxxxx21 374 (2020-09-20 23:32) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 375 (2020-09-20 19:09) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 376 (2020-09-20 22:56) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 377 (2020-09-20 23:36) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 378 (2020-09-20 15:36) def print_moves(board, moves): n='' a=0 b=0 print (' '+str(board[0])+' '+str(board[1])+' '+str(board[2])) print (' '+str(board[3])+' '+str(board[4])+' '+str(board[5])) print (' '+str(board[6])+' '+str(board[7])+' '+str(board[8])) while b < len(moves) : while n != 0 : n = board[a] a = a+1 if moves[b] == 'R' : if a == 1 : board = [board[1],board[0],board[2],board[3],board[4],board[5],board[6],board[7],board[8]] if a == 2 : board = [board[0],board[2],board[1],board[3],board[4],board[5],board[6],board[7],board[8]] if a == 4 : board = [board[0],board[1],board[2],board[4],board[3],board[5],board[6],board[7],board[8]] if a == 5 : board = [board[0],board[1],board[2],board[3],board[5],board[4],board[6],board[7],board[8]] if a == 7 : board = [board[0],board[1],board[2],board[3],board[4],board[5],board[7],board[6],board[8]] if a == 8 : board = [board[0],board[1],board[2],board[3],board[4],board[5],board[6],board[8],board[7]] elif moves[b] == 'L' : if a == 2 : board = [board[1],board[0],board[2],board[3],board[4],board[5],board[6],board[7],board[8]] if a == 3 : board = [board[0],board[2],board[1],board[3],board[4],board[5],board[6],board[7],board[8]] if a == 5 : board = [board[0],board[1],board[2],board[4],board[3],board[5],board[6],board[7],board[8]] if a == 6 : board = [board[0],board[1],board[2],board[3],board[5],board[4],board[6],board[7],board[8]] if a == 8 : board = [board[0],board[1],board[2],board[3],board[4],board[5],board[7],board[6],board[8]] if a == 9 : board = [board[0],board[1],board[2],board[3],board[4],board[5],board[6],board[8],board[7]] elif moves[b] == 'U' : if a == 4 : board = [board[3],board[1],board[2],board[0],board[4],board[5],board[6],board[7],board[8]] if a == 5 : board = [board[0],board[4],board[2],board[3],board[1],board[5],board[6],board[7],board[8]] if a == 6 : board = [board[0],board[1],board[5],board[3],board[4],board[2],board[6],board[7],board[8]] if a == 7 : board = [board[0],board[1],board[2],board[6],board[4],board[5],board[3],board[7],board[8]] if a == 8 : board = [board[0],board[1],board[2],board[3],board[7],board[5],board[6],board[4],board[8]] if a == 9 : board = [board[0],board[1],board[2],board[3],board[4],board[8],board[6],board[7],board[5]] elif moves[b] == 'D' : if a == 1 : board = [board[3],board[1],board[2],board[0],board[4],board[5],board[6],board[7],board[8]] if a == 2 : board = [board[0],board[4],board[2],board[3],board[1],board[5],board[6],board[7],board[8]] if a == 3 : board = [board[0],board[1],board[5],board[3],board[4],board[2],board[6],board[7],board[8]] if a == 4 : board = [board[0],board[1],board[2],board[6],board[4],board[5],board[3],board[7],board[8]] if a == 5 : board = [board[0],board[1],board[2],board[3],board[7],board[5],board[6],board[4],board[8]] if a == 6 : board = [board[0],board[1],board[2],board[3],board[4],board[8],board[6],board[7],board[5]] print ('---------'+' '+moves[b]) print (' '+str(board[0])+' '+str(board[1])+' '+str(board[2])) print (' '+str(board[3])+' '+str(board[4])+' '+str(board[5])) print (' '+str(board[6])+' '+str(board[7])+' '+str(board[8])) b+=1 a=0 n='' #------------------------------------------
# 623xxxxx21 379 (2020-09-20 20:54) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 380 (2020-09-20 22:42) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 381 (2020-09-19 23:08) def print_moves(board, moves): for i in range(len(moves)): a = board.index(0) if moves[i] == 'U' : board[a],board[a-3] = board[a-3],board[a] elif moves[i] == 'D': board[a],board[a+3] = board[a+3],board[a] elif moves[i] == 'R': board[a],board[a+1] = board[a+1],board[a] else: board[a],board[a-1] = board[a-1],board[a] print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) print('--------------------------'+moves[i]) return #------------------------------------------
# 623xxxxx21 382 (2020-09-19 19:54) def print_moves(board, moves): # bonus function: optional import math n = int(math.sqrt(len(board))) for c in moves: out = "" for i in range(n): for j in range(n): out += str(board[(i*n)+j]) + " " out += '\n' print(out[:-1]) print("-------" + c) if 0 in board: l = board.index(0) if c == 'U': board[l], board[l - n] = board[l - n], board[l] elif c == 'D': board[l], board[l + n] = board[l + n], board[l] elif c == 'L': board[l], board[l - 1] = board[l - 1], board[l] elif c == 'R': board[l], board[l + 1] = board[l + 1], board[l] final = "" for i in range(n): for j in range(n): final += str(board[(i*n)+j]) + " " final += '\n' print(final[:-1]) return #------------------------------------------
# 623xxxxx21 383 (2020-09-20 23:53) def print_moves(board, moves): # bonus function: optional: Mission failed :( return #------------------------------------------
# 623xxxxx21 384 (2020-09-20 23:45) def print_moves(board, moves): # bonus function: optional table1 = ' ' for i in range(len(board)): table1 += str(board[i]) + ' ' if (i+1) % (len(board)**0.5) == 0: print(table1[:-1]) table1 = ' ' t = board for z in range(len(moves)): print('-'*3*int(len(board)**0.5), moves[z]) table2 = gen_successors(t + ['']) n = table2.index(moves[z]) t = table2[n-(len(board)):n] table3 = ' ' for i in range(len(t)): table3 += str(t[i]) + ' ' if (i+1) % (len(board)**0.5) == 0: print(table3[:-1]) table3 = ' ' return #------------------------------------------ def gen_successors(node): successors = [] q = int(len(node[:-1])**0.5) k = node.index(0); l = 0; found = False for i in range(1,q+1): if l == k//q: a = k%q - 1; x = k%q + 1; b = k - q; w = k + q if a >= 0: c = node[:-1] c.remove(0); c.insert(k-1,0); successors += c + [node[-1]+ 'L'] if b >= 0: s = node[:-1] s.remove(0); s.insert(b,0) s.remove(s[b+1]); s.insert(k,node[b]) successors += s + [node[-1]+ 'U'] if w < q**2: g = node[:-1] g.remove(0); g.insert(w,0) g.remove(g[w-1]); g.insert(k,node[w]) successors += g + [node[-1]+ 'D'] if x < q: p = node[:-1] p.remove(0); p.insert(k+1,0) successors += p + [node[-1]+ 'R'] found = True if found == True: break else: l += 1 return successors #------------------------------------------
# 623xxxxx21 385 (2020-09-20 17:47) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 386 (2020-09-20 21:46) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 387 (2020-09-20 22:36) def print_moves(board, moves): # bonus function: optional #0 1 2 #3 4 5 #6 7 8 finish=[1,2,3,4,5,6,7,8,0] N=int((len(board))**(1/2)) log=board print_grid(board,N) # make grid move for i in moves: # find 0 in bord for k in range(N*N): if log[k]==0: location=k if i == 'U': log[location], log[location-N]=log[location-N], log[location] print('-'*9+'U') elif i == 'D': log[location], log[location+N]=log[location+N], log[location] print('-'*9+'D') elif i == 'L': log[location], log[location-1]=log[location-1], log[location] print('-'*9+'L') elif i == 'R': log[location], log[location+1]=log[location+1], log[location] print('-'*9+'R') #print('log',log) print_grid(log,N) # ------------------------------------------ def print_grid(bord,N): # for easy grid output for j in range(N): line='' for i in range(N): line+=' ' line+=str(board[i+N*j]) line+=' ' print(line)
# 623xxxxx21 388 (2020-09-20 19:08) def print_moves(board, moves): return #------------------------------------------
# 623xxxxx21 389 (2020-09-20 23:06) def print_moves(board, moves): finish=[1,2,3,4,5,6,7,8,0] N=int((len(board))**(1/2)) log=board print_grid(board,N) for i in moves: for k in range(N*N): if log[k]==0: location=k if i == 'U': log[location], log[location-N]=log[location-N], log[location] print('-'*9+'U') elif i == 'D': log[location], log[location+N]=log[location+N], log[location] print('-'*9+'D') elif i == 'L': log[location], log[location-1]=log[location-1], log[location] print('-'*9+'L') elif i == 'R': log[location], log[location+1]=log[location+1], log[location] print('-'*9+'R') print_grid(log,N) # ------------------------------------------ def print_grid(bord,N): for y in range(N): line='' for i in range(N): line+=' ' line+=str(board[i+N*y]) line+=' ' print(line)
# 623xxxxx21 390 (2020-09-20 23:54) def print_moves(board, moves): # bonus function: optional x1 = ' ' for i in range(len(board)): x1 += str(board[i]) + ' ' if (i+1) % (len(board)**0.5) == 0: print(x1[:-1]) x1 = ' ' t = board for z in range(len(moves)): print('-'*3*int(len(board)**0.5), moves[z]) x2 = gen_successors(t + ['']) n = x2.index(moves[z]) t = x2[n-(len(board)):n] x3 = ' ' for i in range(len(t)): x3 += str(t[i]) + ' ' if (i+1) % (len(board)**0.5) == 0: print(x3[:-1]) x3 = ' ' return #------------------------------------------ def gen_successors(node): successors = [] size = int(len(node[:-1])**0.5) num = node.index(0) add = 0 found = False for i in range(1,size+1): if add == num//size: a = num%size - 1 b = num%size + 1 c = num - size d = num + size if a >= 0: e = node[:-1] e.remove(0) e.insert(num-1,0) successors += e + [node[-1]+ 'L'] if c >= 0: f = node[:-1] f.remove(0) f.insert(c,0) f.remove(f[c+1]) f.insert(num,node[c]) successors += f + [node[-1]+ 'U'] if d < size**2: g = node[:-1] g.remove(0) g.insert(d,0) g.remove(g[d-1]) g.insert(num,node[d]) successors += g + [node[-1]+ 'D'] if b < size: h = node[:-1] h.remove(0) h.insert(num+1,0) successors += h + [node[-1]+ 'R'] found = True if found == True: break else: add += 1 return successors #------------------------------------------
# 623xxxxx21 391 (2020-09-20 20:59) def print_moves(board, moves): # bonus function: optional table1 = ' ' for i in range(len(board)): table1 += str(board[i]) + ' ' if (i+1) % (len(board)**0.5) == 0: print(table1[:-1]) table1 = ' ' t = board for z in range(len(moves)): print('-'*3*int(len(board)**0.5), moves[z]) table2 = gen_successors(t + ['']) n = table2.index(moves[z]) t = table2[n-(len(board)):n] table3 = ' ' for i in range(len(t)): table3 += str(t[i]) + ' ' if (i+1) % (len(board)**0.5) == 0: print(table3[:-1]) table3 = ' ' return #------------------------------------------ def gen_successors(node): successors = [] a = int(len(node[:-1])**0.5) b = node.index(0); m = 0; found = False for i in range(1,a+1): if m == b//a: x = b%a - 1; y = b%a + 1; z = b - a; w = b + a if x >= 0: c = node[:-1] c.remove(0); c.insert(b-1,0); successors += c + [node[-1]+ 'L'] if z >= 0: s = node[:-1] s.remove(0); s.insert(z,0) s.remove(s[z+1]); s.insert(b,node[z]) successors += s + [node[-1]+ 'U'] if w < a**2: g = node[:-1] g.remove(0); g.insert(w,0) g.remove(g[w-1]); g.insert(b,node[w]) successors += g + [node[-1]+ 'D'] if y < a: p = node[:-1] p.remove(0); p.insert(b+1,0) successors += p + [node[-1]+ 'R'] found = True if found == True: break else: m += 1 return successors #------------------------------------------
# 623xxxxx21 392 (2020-09-20 15:54) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 393 (2020-09-20 22:24) def print_moves(board, moves): N = int((len(board)**0.5)) for k in moves : ind = board.index(0) for i in range(N) : s = [] for j in range(N) : s.append(str(board[(i*N)+j]) + " ") print(" ".join(s)) print("-"*(N*3) + " " + k) if k == "U" : board[ind],board[ind-N] = board[ind-N],board[ind] elif k == "D" : board[ind],board[ind+N] = board[ind+N],board[ind] elif k == "L" : board[ind],board[ind-1] = board[ind-1],board[ind] elif k == "R" : board[ind],board[ind+1] = board[ind+1],board[ind] for i in range(N) : s = [] for j in range(N) : s.append(str(board[(i*N)+j]) + " ") print(" ".join(s)) return #------------------------------------------
# 623xxxxx21 394 (2020-09-20 21:15) def print_moves(board, moves): # bonus function: optional first_table = ' ' for i in range(len(board)): first_table += str(board[i]) + ' ' if (i+1) % (len(board)**0.5) == 0: print(first_table[:-1]) first_table = ' ' t = board for z in range(len(moves)): print('-'*3*int(len(board)**0.5), moves[z]) table = gen_successors(t + ['']) n = table.index(moves[z]) t = table[n-(len(board)):n] another_table = ' ' for i in range(len(t)): another_table += str(t[i]) + ' ' if (i+1) % (len(board)**0.5) == 0: print(another_table[:-1]) another_table = ' ' return #------------------------------------------ def gen_successors(node): successors = [] n = int(len(node[:-1])**0.5) c = node.index(0); m = 0; found = False for i in range(1,n+1): if m == c//n: x = c%n - 1; y = c%n + 1; z = c - n; w = c + n if x >= 0: g = node[:-1] g.remove(0); g.insert(c-1,0); successors += g + [node[-1]+ 'L'] if z >= 0: l = node[:-1] l.remove(0); l.insert(z,0) l.remove(l[z+1]); l.insert(c,node[z]) successors += l + [node[-1]+ 'U'] if w < n**2: k = node[:-1] k.remove(0); k.insert(w,0) k.remove(k[w-1]); k.insert(c,node[w]) successors += k + [node[-1]+ 'D'] if y < n: h = node[:-1] h.remove(0); h.insert(c+1,0) successors += h + [node[-1]+ 'R'] found = True if found == True: break else: m += 1 return successors #------------------------------------------
# 623xxxxx21 395 (2020-09-19 22:23) def print_moves(board, moves): # bonus function: optional L = int((len(board))**0.5) for i in range(L): print(" " + " ".join(str(x) for x in board[i*L:i*L+ L])) for form in moves: print("--------- " + form) pos = board.index(0) if form == "U": board[pos], board[pos-L] = board[pos-L], board[pos] if form == "D": board[pos], board[pos+L] = board[pos+L], board[pos] if form == "L": board[pos], board[pos-1] = board[pos-1], board[pos] if form == "R": board[pos], board[pos+1] = board[pos+1], board[pos] for i in range(L): print(" " + " ".join(str(x) for x in board[i*L:i*L+ L])) return board #------------------------------------------
# 623xxxxx21 396 (2020-09-20 20:42) def print_moves(board, moves): # bonus function: optional bb = '' cc = 0 for j in board: #print board bb += str(j) + ' ' cc += 1 if cc == 3: print(bb) cc = 0 bb = '' for i in moves: pos = board.index(0) if i == 'U': board[pos],board[pos-3] = board[pos-3],board[pos] b = '' c = 0 print('--------- U') for i in board: b += str(i) + ' ' c += 1 if c == 3: print(b) c = 0 b = '' if i == 'D': board[pos],board[pos+3] = board[pos+3],board[pos] b = '' c = 0 print('--------- D') for i in board: b += str(i) + ' ' c += 1 if c == 3: print(b) c = 0 b = '' if i == 'R': board[pos],board[pos+1] = board[pos+1],board[pos] b = '' c = 0 print('--------- R') for i in board: b += str(i) + ' ' c += 1 if c == 3: print(b) c = 0 b = '' if i == 'L': board[pos],board[pos-1] = board[pos-1],board[pos] b = '' c = 0 print('--------- L') for i in board: b += str(i) + ' ' c += 1 if c == 3: print(b) c = 0 b = '' return #------------------------------------------
# 623xxxxx21 397 (2020-09-20 21:32) def print_moves(board, moves): # bonus function: optional table1 = ' ' for i in range(len(board)): table1 += str(board[i]) + ' ' if (i+1) % (len(board)**(1/2)) == 0: print(table1[:-1]) table1 = ' ' m = board for z in range(len(moves)): print('-'*3*int(len(board)**(1/2)), moves[z]) table2 = gen_successors(m + ['']) n = table2.index(moves[z]) m = table2[n-(len(board)):n] table3 = ' ' for i in range(len(m)): table3 += str(m[i]) + ' ' if (i+1) % (len(board)**(1/2)) == 0: print(table3[:-1]) table3 = ' ' return #------------------------------------------ def gen_successors(node): successors = [] x = int(len(node[:-1])**(1/2)) y = node.index(0); m = 0; found = False for i in range(1,x+1): if m == y//x: a = y%x - 1; b = y%x + 1; z = y - x; w = y + x if a >= 0: c = node[:-1] c.remove(0); c.insert(y-1,0); successors += c + [node[-1]+ 'L'] if z >= 0: s = node[:-1] s.remove(0); s.insert(z,0) s.remove(s[z+1]); s.insert(y,node[z]) successors += s + [node[-1]+ 'U'] if w < x**2: g = node[:-1] g.remove(0); g.insert(w,0) g.remove(g[w-1]); g.insert(y,node[w]) successors += g + [node[-1]+ 'D'] if b < x: p = node[:-1] p.remove(0); p.insert(y+1,0) successors += p + [node[-1]+ 'R'] found = True if found == True: break else: m += 1 return successors #------------------------------------------
# 623xxxxx21 398 (2020-09-20 23:43) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 399 (2020-09-20 23:48) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 400 (2020-09-20 23:55) def print_moves(board, moves): table1 = ' ' for i in range(len(board)): table1 += str(board[i]) + ' ' if (i+1) % (len(board)**0.5) == 0: print(table1[:-1]) table1 = ' ' t = board for z in range(len(moves)): print('-'*3*int(len(board)**0.5), moves[z]) table2 = gen_successors(t + ['']) n = table2.index(moves[z]) t = table2[n-(len(board)):n] table3 = ' ' for i in range(len(t)): table3 += str(t[i]) + ' ' if (i+1) % (len(board)**0.5) == 0: print(table3[:-1]) table3 = ' ' return def gen_successors(node): successors = [] a = int(len(node[:-1])**0.5) b = node.index(0); m = 0; found = False for i in range(1,a+1): if m == b//a: x = b%a - 1; y = b%a + 1; z = b - a; w = b + a if x >= 0: c = node[:-1] c.remove(0); c.insert(b-1,0); successors += c + [node[-1]+ 'L'] if z >= 0: s = node[:-1] s.remove(0); s.insert(z,0) s.remove(s[z+1]); s.insert(b,node[z]) successors += s + [node[-1]+ 'U'] if w < a**2: g = node[:-1] g.remove(0); g.insert(w,0) g.remove(g[w-1]); g.insert(b,node[w]) successors += g + [node[-1]+ 'D'] if y < a: p = node[:-1] p.remove(0); p.insert(b+1,0) successors += p + [node[-1]+ 'R'] found = True if found == True: break else: m += 1 return successors
# 623xxxxx21 401 (2020-09-20 22:21) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 623xxxxx21 402 (2020-09-20 23:53) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 403 (2020-09-20 15:35) def print_moves(board, moves): # bonus function: optional t = list(board) table(t) for i in moves : if i == "R": k = t.index(0) print("--------- R") t[k],t[k+1]=t[k+1],t[k] table(t) elif i == "L": k = t.index(0) print("--------- L") t[k],t[k-1]=t[k-1],t[k] table(t) elif i == "U": k = t.index(0) print("--------- U") t[k],t[k-3]=t[k-3],t[k] table(t) elif i == "D": k = t.index(0) print("--------- D") t[k],t[k+3]=t[k+3],t[k] table(t) return #------------------------------------------ def table(b) : print(" "+str(b[0])+" "+str(b[1])+" "+str(b[2])) print(" "+str(b[3])+" "+str(b[4])+" "+str(b[5])) print(" "+str(b[6])+" "+str(b[7])+" "+str(b[8])) #------------------------------------------
# 633xxxxx21 404 (2020-09-20 19:35) def print_moves(board, moves): # bonus function: optional n = int(len(board) ** (0.5)) for r in range(n - 1, int(n**2), n): for c in range(r - (n - 1), r + 1): print(board[c], end = ' ') if r == c: print('') for r in range(len(moves)): print('------------',moves[r]) if moves[r] == 'L': pos_zero = board.index(0) board[pos_zero],board[pos_zero-1] = board[pos_zero-1],board[pos_zero] if moves[r] == 'R': pos_zero = board.index(0) board[pos_zero],board[pos_zero+1] = board[pos_zero+1],board[pos_zero] if moves[r] == 'U': pos_zero = board.index(0) board[pos_zero],board[pos_zero-n] = board[pos_zero-n],board[pos_zero] if moves[r] == 'D': pos_zero = board.index(0) board[pos_zero],board[pos_zero+n] = board[pos_zero+n],board[pos_zero] for r in range(n - 1, int(n**2), n): for c in range(r - (n - 1), r + 1): print(board[c], end = ' ') if r == c: print('') return #------------------------------------------
# 633xxxxx21 405 (2020-09-19 23:32) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 406 (2020-09-20 21:48) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 407 (2020-09-19 16:18) def print_moves(board, moves): # bonus function: optional N = len(board) n = int(N**0.5) # for beautiful spacing boardStr = list(board) for i in range(N): if boardStr[i] < 10: boardStr[i] = str(boardStr[i]) + " " elif boardStr[i] < 100: boardStr[i] = str(boardStr[i]) + " " for i in range(1, n+1): print(" ".join(boardStr[i*n-n:i*n])) for i in range(len(moves)): index = board.index(0) if moves[i] == "U": board[index], board[index-n] = board[index-n], board[index] elif moves[i] == "L": board[index], board[index-1] = board[index-1], board[index] elif moves[i] == "R": board[index], board[index+1] = board[index+1], board[index] elif moves[i] == "D": board[index], board[index+n] = board[index+n], board[index] # for beautiful spacing boardStr = list(board) for j in range(N): if boardStr[j] < 10: boardStr[j] = str(boardStr[j]) + " " elif boardStr[j] < 100: boardStr[j] = str(boardStr[j]) + " " print("-"*(4*n) + moves[i]) for j in range(1, n+1): print(" ".join(boardStr[j*n-n:j*n])) return #------------------------------------------
# 633xxxxx21 408 (2020-09-20 21:10) def print_moves(board, moves): for i in range(len(moves)): print("",board[0],"",board[1],"",board[2]) print("",board[3],"",board[4],"",board[5]) print("",board[6],"",board[7],"",board[8]) print("--------------", moves[i]) s = board.index(0) if moves[i] == "D": board.remove(0) board.insert(s+2,0) board.insert(s,board[s+3]) board.pop(s+4) elif moves[i] == "U" : board.remove(0) board.insert(s-3,0) board.insert(s,board[s-2]) board.pop(s-2) elif moves[i] == "R": board.remove(0) board.insert(s+1,0) elif moves[i] == "L": board.remove(0) board.insert(s-1,0) print("",board[0],"",board[1],"",board[2]) print("",board[3],"",board[4],"",board[5]) print("",board[6],"",board[7],"",board[8]) return #------------------------------------------
# 633xxxxx21 409 (2020-09-20 21:09) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 410 (2020-09-20 08:16) def print_moves(board, moves): # bonus function: optional N = int((len(board))**0.5) nb = [] for l in board : nb.append(str(l)) for i in moves : if i == 'D' : for j in range(N) : print('' ," ".join(nb[j*N:(j+1)*N])) print("---------" , i) x = nb.index('0') (nb[x],nb[x+N]) = (nb[x+N],nb[x]) elif i == 'R' : for j in range(N) : print('' ," ".join(nb[j*N:(j+1)*N])) print("---------" , i) x = nb.index('0') (nb[x],nb[x+1]) = (nb[x+1],nb[x]) elif i == 'L' : for j in range(N) : print('' ," ".join(nb[j*N:(j+1)*N])) print("---------" , i) x = nb.index('0') (nb[x],nb[x-1]) = (nb[x-1],nb[x]) elif i == 'U' : for j in range(N) : print('' ," ".join(nb[j*N:(j+1)*N])) print("---------" , i) x = nb.index('0') (nb[x],nb[x-N]) = (nb[x-N],nb[x]) for j in range(N) : print('' ," ".join(nb[j*N:(j+1)*N])) return #------------------------------------------
# 633xxxxx21 411 (2020-09-20 21:02) def print_moves(board, moves): result = board print_board(result) for i in moves: index_0 = result.index(0) print("--------- "+i) if i == "U": result[index_0], result[index_0-divition] = result[index_0-divition], result[index_0] elif i == "D": result[index_0], result[index_0+divition] = result[index_0+divition], result[index_0] elif i == "L": result[index_0], result[index_0-1] = result[index_0-1], result[index_0] elif i == "R": result[index_0], result[index_0+1] = result[index_0+1], result[index_0] print_board(result) return #------------------------------------------ def print_board(board): for i in range(divition): for j in range(divition): print(board[i*divition+j], end= " ") print()
# 633xxxxx21 412 (2020-09-20 21:26) def print_moves(board, moves): # bonus function: optional nn = int(len(board)**0.5) #3 numnum = len(board) #9 q = board.index(0) #8 z = list(board) for k in range(0,numnum,nn): c = k+nn-1 while k<c: print(z[k],end=" ") k+=1 print(z[k]) for c in moves: if c=='U': print("-"*nn**2+"U") a = z[q-3] z.pop(q-3) z.insert(q-3,0) z.pop(q) z.insert(q,a) for k in range(0,numnum,nn): c = k+nn-1 while k<c: print(z[k],end=" ") k+=1 print(z[k]) q = z.index(0) if c=='D': print("-"*nn**2+"D") a = z[q+3] z.pop(q+3) z.insert(q+3,0) z.pop(q) z.insert(q,a) for k in range(0,numnum,nn): c = k+nn-1 while k<c: print(z[k],end=" ") k+=1 print(z[k]) q = z.index(0) if c=='L': print("-"*nn**2+"L") a = z[q-1] z.pop(q-1) z.insert(q-1,0) z.pop(q) z.insert(q,a) for k in range(0,numnum,nn): c = k+nn-1 while k<c: print(z[k],end=" ") k+=1 print(z[k]) q = z.index(0) if c=='R': print("-"*nn**2+"R") a = z[q+1] z.pop(q+1) z.insert(q+1,0) z.pop(q) z.insert(q,a) for k in range(0,numnum,nn): c = k+nn-1 while k<c: print(z[k],end=" ") k+=1 print(z[k]) q = z.index(0) return #------------------------------------------
# 633xxxxx21 413 (2020-09-20 03:30) def print_moves(board, moves): # bonus function: optional dash = "-" size = int(len(board)**0.5) position = board.index(0) progress_board = "" for action in moves: for i in range(0,len(board),size): new_sequence = "" for index_of_size in range(size): new_sequence += f"{board[i + index_of_size]} " progress_board += (" "+new_sequence+"\n") progress_board += (f"{dash*(size**2)} {action}\n") if action == "U": board[position] = board[position - size] board[position - size] = 0 position = position - size elif action == "D": board[position] = board[position + size] board[position + size] = 0 position = position + size elif action == "L": board[position] = board[position - 1] board[position - 1] = 0 position = position - 1 elif action == "R": board[position] = board[position + 1] board[position + 1] = 0 position = position + 1 for i in range(0,len(board),size): new_sequence = "" for index_of_size in range(size): new_sequence += f"{board[i + index_of_size]} " progress_board += (" "+new_sequence+"\n") print(progress_board) return #------------------------------------------
# 633xxxxx21 414 (2020-09-20 11:55) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 415 (2020-09-20 18:57) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 416 (2020-09-20 17:20) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 417 (2020-09-20 23:25) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 418 (2020-09-20 20:56) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 419 (2020-09-16 11:51) def print_moves(board, moves): # bonus function: optional print(f' {board[0]} {board[1]} {board[2]} \n {board[3]} {board[4]} {board[5]} \n {board[6]} {board[7]} {board[8]} ') for c in moves: print(f'--------- {c}') i = board.index(0) if c == 'U': board[i], board[i-3] = board[i-3], board[i] elif c == 'D': board[i], board[i+3] = board[i+3], board[i] elif c == 'L': board[i], board[i-1] = board[i-1], board[i] elif c == 'R': board[i], board[i+1] = board[i+1], board[i] print(f' {board[0]} {board[1]} {board[2]} \n {board[3]} {board[4]} {board[5]} \n {board[6]} {board[7]} {board[8]} ') return #------------------------------------------
# 633xxxxx21 420 (2020-09-20 14:47) def print_moves (board, moves): # bonus function: optional ps = board.index(0) for ix in range(len(board)) : board[ix] = str(board[ix]) showes = [] lb = int(len(board)**0.5) for ix in range(0,len(board),lb) : showes = board[ix:ix+lb] print("\t".join(showes)) showes = [] if moves != "" : for es in range(len(moves)) : print("------------------ "+moves[es]) if moves[es] == "R": board[ps+1],board[ps] = board[ps],board[ps+1] elif moves[es] == "L": board[ps-1],board[ps] = board[ps],board[ps-1] elif moves[es] == "U": board[ps-lb],board[ps] = board[ps],board[ps-lb] elif moves[es] == "D": board[ps+lb],board[ps] = board[ps],board[ps+lb] for ix in range(0,len(board),lb) : showes = board[ix:ix+lb] print("\t".join(showes)) showes = [] ps = board.index("0") if "0" == board[-1]: break if es < (len(moves)-1) : print("------------------ "+moves[len(moves)-1]) return # ------------------------------------------
# 633xxxxx21 421 (2020-09-20 22:44) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 422 (2020-09-18 15:27) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 423 (2020-09-20 20:37) def print_moves(board, moves): # bonus function: optional board=[str(e) for e in board] key=int(len(board)**0.5) for i in range (0,len(board),key): print(' '.join(board[i:i+key])) for e in moves: print("---------",e) if '0' in board: idx = board.index('0') if e =='U': board[idx],board[idx-key]=board[idx-key],board[idx] elif e =='D': board[idx],board[idx+key]=board[idx+key],board[idx] elif e =='R': board[idx],board[idx+1]=board[idx+1],board[idx] elif e =='L': board[idx],board[idx-1]=board[idx-1],board[idx] for i in range (0,len(board),key): print(' '.join(board[i:i+key])) return #------------------------------------------
# 633xxxxx21 424 (2020-09-20 02:36) def print_moves(board, moves): # bonus function: optional return #-------------------------------------------
# 633xxxxx21 425 (2020-09-20 11:38) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 426 (2020-09-20 23:36) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 427 (2020-09-20 20:52) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 428 (2020-09-20 22:52) def print_moves(board, moves): for c in moves: print_board(board, c) make_move2(board,c) c = '' print_board(board, c) return # ------------------------------------------ def make_move2(board,move): loc = board.index(0) N = int((len(board))**(1/2)) if move == 'U': (board[loc],board[loc-N]) = (board[loc-N],board[loc]) elif move == 'D': (board[loc], board[(loc + N)]) = (board[(loc + N)], board[loc]) elif move == 'R': (board[loc], board[loc + 1]) = (board[loc + 1], board[loc]) else: (board[loc], board[loc - 1]) = (board[loc - 1], board[loc]) def print_board(board,c): n = len(board) N = int(n**(1/2)) for i in range(N): output = '' for j in range(N): output = output + str(board[i*3+j]) + ' ' print(output) print('------',c) # ------------------------------------------
# 633xxxxx21 429 (2020-09-20 10:55) def print_moves(board, moves): # bonus function: optional NxN = int((len(board))**(1/2)) inb = 0 brdStr = '' for brd in board : if inb != 0 and inb % NxN == 0 : print(brdStr) brdStr = '' brdStr += str(brd) + ' ' inb += 1 print(brdStr) for move in moves : inb = 0 for n in board: if n == 0 : if move == 'D' : board[inb], board[inb+NxN] = board[inb+NxN], board[inb] elif move == 'U' : board[inb], board[inb-NxN] = board[inb-NxN], board[inb] elif move == 'L' : board[inb], board[inb-1] = board[inb-1], board[inb] elif move == 'R' : board[inb], board[inb+1] = board[inb+1], board[inb] break inb += 1 print('--------- ' + move) inb = 0 brdStr = '' for brd in board : if inb != 0 and inb % NxN == 0 : print(brdStr) brdStr = '' brdStr += str(brd) + ' ' inb += 1 print(brdStr) return #------------------------------------------
# 633xxxxx21 430 (2020-09-19 21:32) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 431 (2020-09-20 14:26) def print_moves(board, moves): # bonus function: optional N = 1 while N*N != len(board): N += 1 for k in range((len(board))): print(str(board[k])+" ", end=" ") if (k+1)%N == 0: print("\n") for i in range(len(moves)): collect = board.index(0) # up if moves[i] == "U": board[collect], board[collect-N] = board[collect-N], board[collect] # down if moves[i] == "D": board[collect], board[collect+N] = board[collect+N], board[collect] # left if moves[i] == "L": board[collect], board[collect-1] = board[collect-1], board[collect] # right if moves[i] == "R": board[collect], board[collect+1] = board[collect+1], board[collect] print("-"*(N*3)+moves[i]) for j in range((len(board))): print(str(board[j])+" ", end=" ") if (j+1)%N == 0: print("\n") #------------------------------------------
# 633xxxxx21 432 (2020-09-20 20:14) def print_moves(board, moves): # bonus function: optional f = len(board) N = int(math.sqrt(f)) for o in range(N) : for p in range(N) : print(board[p+(o*N)],end = ' ') print() for i in moves : print('-'*(2*N-1)+i) k = board.index(0) if i == 'U' : board[k],board[k-N] = board[k-N],board[k] if i == 'D': board[k],board[k+N] = board[k+N],board[k] if i == 'L': board[k],board[k-1] = board[k-1],board[k] if i == 'R': board[k],board[k+1] = board[k+1],board[k] for o in range(N) : for p in range(N) : print(board[p+(o*N)],end = ' ') print() return #------------------------------------------
# 633xxxxx21 433 (2020-09-19 23:32) def print_moves(board, moves): # bonus function: optional N = int((len(board))**(1/2)) print('\n') print('Bonus',end='') print('\n') for j in range(N): if j == 0: n = j elif j>0: n += N k = 0 while k <= N-1: print(board[n+k],'',end='') k += 1 print('') for i in range(len(moves)): print('---------------'+moves[i]) p = board.index(0) if moves[i]== 'D': board[p],board[p+N] = board[p+N],board[p] elif moves[i]=='R': board[p],board[p+1] = board[p+1],board[p] elif moves[i]=='U': board[p],board[p-N] = board[p-N],board[p] elif moves[i]=='L': board[p],board[p-1] = board[p-1],board[p] for j in range(N): if j == 0: n = j elif j>0: n += N k = 0 while k <= N-1: print(board[n+k],'',end='') k += 1 print('') return #------------------------------------------
# 633xxxxx21 434 (2020-09-20 19:10) def print_moves(board, moves): # print from moves N = int(len(board) ** (0.5)) # square matrix for i in range(N - 1, int(N**2), N): for j in range(i - (N - 1), i + 1): print(board[j], end = ' ') if i == j: print('') for i in range(len(moves)): print('------------',moves[i]) if moves[i] == 'L': pos_zero = board.index(0) board[pos_zero],board[pos_zero-1] = board[pos_zero-1],board[pos_zero] if moves[i] == 'R': pos_zero = board.index(0) board[pos_zero],board[pos_zero+1] = board[pos_zero+1],board[pos_zero] if moves[i] == 'U': pos_zero = board.index(0) board[pos_zero],board[pos_zero-N] = board[pos_zero-N],board[pos_zero] if moves[i] == 'D': pos_zero = board.index(0) board[pos_zero],board[pos_zero+N] = board[pos_zero+N],board[pos_zero] for i in range(N - 1, int(N**2), N): for j in range(i - (N - 1), i + 1): print(board[j], end = ' ') if i == j: print('') return #------------------------------------------
# 633xxxxx21 435 (2020-09-20 20:14) def print_moves(board, moves): # bonus function: optional if len(board)==9: node=board print(node[0],node[1],node[2]) print(node[3],node[4],node[5]) print(node[6],node[7],node[8]) nnode=list(node) for c in moves: pos=nnode.index(0) if c=='L': nnode[pos],nnode[pos-1]=nnode[pos-1],nnode[pos] print('------'+c) print(nnode[0],nnode[1],nnode[2]) print(nnode[3],nnode[4],nnode[5]) print(nnode[6],nnode[7],nnode[8]) elif c=='R': nnode[pos],nnode[pos+1]=nnode[pos+1],nnode[pos] print('------'+c) print(nnode[0],nnode[1],nnode[2]) print(nnode[3],nnode[4],nnode[5]) print(nnode[6],nnode[7],nnode[8]) elif c=='D': nnode[pos],nnode[pos+3]=nnode[pos+3],nnode[pos] print('------'+c) print(nnode[0],nnode[1],nnode[2]) print(nnode[3],nnode[4],nnode[5]) print(nnode[6],nnode[7],nnode[8]) elif c=='U': nnode[pos],nnode[pos-3]=nnode[pos-3],nnode[pos] print('------'+c) print(nnode[0],nnode[1],nnode[2]) print(nnode[3],nnode[4],nnode[5]) print(nnode[6],nnode[7],nnode[8]) elif len(board)!=9: a=int((len(board))**0.5) node=board for i in range(a): blank=board[i*a:i*a+a] print(' '+ ' '.join(str(n) for n in blank)) for c in moves: pos=board.index(0) if c=='L': node[pos],node[pos-1]=node[pos-1],node[pos] print('------'+c) elif c=='R': node[pos],node[pos+1]=node[pos+1],node[pos] print('------'+c) elif c=='D': node[pos],node[pos+a]=node[pos+a],node[pos] print('------'+c) elif c=='U': node[pos],node[pos-a]=node[pos-a],node[pos] print('------'+c) for i in range(a): blank=board[i*a:i*a+a] print(' '+ ' '.join(str(n) for n in blank)) return #------------------------------------------
# 633xxxxx21 436 (2020-09-20 20:01) def print_moves(board, moves): print() print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) for e in moves: if e == 'D': a = board.index(0) board[a],board[a+3] = board[a+3],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'L': a = board.index(0) board[a],board[a-1] = board[a-1],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'U': a = board.index(0) board[a],board[a-3] = board[a-3],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'R': a = board.index(0) board[a],board[a+1] = board[a+1],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) return #------------------------------------------
# 633xxxxx21 437 (2020-09-20 13:10) def print_moves(board, moves): # bonus function: optional for i in range(0,7,3): print( ' ' + str(board[i]) + ' ' + str(board[i+1]) + ' ' + str(board[i+2])) for i in moves: if i == 'U': inx = board.index(0) n = board[inx-3] board[inx-3] = 0 board[inx] = n elif i == 'D': inx = board.index(0) n = board[(inx+3)] board[inx+3] = 0 board[inx] = n elif i == 'R': inx = board.index(0) n = board[inx+1] board[inx+1] = 0 board[inx] = n elif i == 'L': inx = board.index(0) n = board[inx-1] board[inx-1] = 0 board[inx] = n print('-'*9 + ' ' + i) for w in range(0,7,3): print( ' ' + str(board[w]) + ' ' + str(board[w+1]) + ' ' + str(board[w+2])) return #------------------------------------------
# 633xxxxx21 438 (2020-09-20 16:15) def print_moves(board, moves): # bonus function: optional N = int(len(board)**(0.5)) for k in range(N-1,int(N**2),N): for m in range(k-(N-1),k+1): print(board[m],end=" ") if m == k: print('') for e in moves: print('-----------',e) if e == 'L': x = board.index(0) board[x],board[x-1] = board[x-1],board[x] if e == 'R': x = board.index(0) board[x],board[x+1] = board[x+1],board[x] if e == 'U': x = board.index(0) board[x],board[x-N] = board[x-N],board[x] if e == 'D': x = board.index(0) board[x],board[x+N] = board[x+N],board[x] for k in range(N-1,int(N**2),N): for m in range(k-(N-1),k+1): print(board[m],end=" ") if m == k: print('') return #------------------------------------------
# 633xxxxx21 439 (2020-09-20 19:44) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 440 (2020-09-20 23:41) def print_moves(board, moves): for i in range(0,len(board),3): s = [] for j in range(i,i+3): s.append(str(board[j])) print(" ".join(s)) for i in range(len(moves)): b = board.index(0) if b == 0 : if moves[i] == 'D': board[0],board[3] = board[3],board[0] if moves[i] == 'R': board[0],board[1] = board[1],board[0] elif b == 1 : if moves[i] == 'L': board[1],board[0] = board[0],board[1] if moves[i] == 'D': board[1],board[4] = board[4],board[1] if moves[i] == 'R': board[1],board[2] = board[2],board[1] elif b == 2 : if moves[i] == 'L': board[2],board[1] = board[1],board[2] if moves[i] == 'D': board[2],board[5] = board[5],board[2] elif b == 3 : if moves[i] == 'U': board[3],board[0] = board[0],board[3] if moves[i] == 'R': board[3],board[4] = board[4],board[3] if moves[i] == 'D': board[3],board[6] = board[6],board[3] elif b == 4 : if moves[i] == 'L': board[4],board[3] = board[3],board[4] if moves[i] == 'U': board[4],board[1] = board[1],board[4] if moves[i] == 'R': board[4],board[5] = board[5],board[4] if moves[i] == 'D': board[4],board[7] = board[7],board[4] elif b == 5 : if moves[i] == 'U': board[5],board[2] = board[2],board[5] if moves[i] == 'L': board[5],board[4] = board[4],board[5] if moves[i] == 'D': board[5],board[8] = board[8],board[5] elif b == 6 : if moves[i] == 'U': board[6],board[3] = board[3],board[6] if moves[i] == 'R': board[6],board[7] = board[7],board[6] elif b == 7 : if moves[i] == 'L': board[7],board[6] = board[6],board[7] if moves[i] == 'U': board[7],board[4] = board[4],board[7] if moves[i] == 'R': board[7],board[8] = board[8],board[7] elif b == 8 : if moves[i] =='L': board[8],board[7] = board[7],board[8] if moves[i] == 'U': board[8],board[5] = board[5],board[8] print('--------- ' + moves[i]) for i in range(0,len(board),3): s = [] for j in range(i,i+3): s.append(str(board[j])) print(" ".join(s)) return #------------------------------------------
# 633xxxxx21 441 (2020-09-20 22:08) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 442 (2020-09-20 18:35) def print_moves(board, moves): # bonus function: optional print(" "+str(board[0])+" "+str(board[1])+" "+str(board[2])) print(" "+str(board[3])+" "+str(board[4])+" "+str(board[5])) print(" "+str(board[6])+" "+str(board[7])+" "+str(board[8])) for element in moves : zeroIndex = board.index(0) print("--------- ",element) if element == 'U' : board[zeroIndex],board[zeroIndex-3] = board[zeroIndex-3],board[zeroIndex] elif element == 'L' : board[zeroIndex],board[zeroIndex-1] = board[zeroIndex-1],board[zeroIndex] elif element == 'R' : board[zeroIndex],board[zeroIndex+1] = board[zeroIndex+1],board[zeroIndex] elif element == 'D' : board[zeroIndex],board[zeroIndex+3] = board[zeroIndex+3],board[zeroIndex] print(" "+str(board[0])+" "+str(board[1])+" "+str(board[2])) print(" "+str(board[3])+" "+str(board[4])+" "+str(board[5])) print(" "+str(board[6])+" "+str(board[7])+" "+str(board[8])) #------------------------------------------
# 633xxxxx21 443 (2020-09-17 15:08) def print_moves(board, moves): # bonus function: optional print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) for q in moves: print("-"*9,q) f=board.index(0) if q=="D": board[f],board[f+3]=board[f+3],board[f] elif q=="R": board[f], board[f + 1] = board[f + 1], board[f] elif q=="L": board[f],board[f-1]=board[f-1],board[f] elif q=="U": board[f], board[f - 3] = board[f - 3], board[f] print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) return # ------------------------------------------
# 633xxxxx21 444 (2020-09-20 00:43) def print_moves(board, moves): # bonus function: optional #--------------BONUS MARK-------------- return #------------------------------------------
# 633xxxxx21 445 (2020-09-19 15:38) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 446 (2020-09-18 20:06) def print_moves(board, moves): for e in range(0,len(board),3): print(board[e],board[e+1],board[e+2]) A = board[:] zero_index = A.index(0) for e in range(len(moves)): print("---------",moves[e]) if moves[e] == "R" : A[zero_index],A[zero_index+1] = A[zero_index+1],A[zero_index] elif moves[e] == "L" : A[zero_index],A[zero_index-1] = A[zero_index-1],A[zero_index] elif moves[e] == "U" : A[zero_index],A[zero_index-3] = A[zero_index-3],A[zero_index] elif moves[e] == "D" : A[zero_index],A[zero_index+3] = A[zero_index+3],A[zero_index] for e in range(0,len(A),3): print(A[e],A[e+1],A[e+2]) zero_index = A.index(0) return #------------------------------------------
# 633xxxxx21 447 (2020-09-17 22:36) def print_moves(board, moves): # bonus function: optional y = int((len(board))**(1/2)) for i in range(y): print(' '.join(str(x) for x in board[i*y:i*y+y])) for e in moves : print('----------',e) x = board.index(0) if e == 'U' : board[x],board[x-y] = board[x-y],board[x] if e == 'D' : board[x],board[x+y] = board[x+y],board[x] if e == 'L' : board[x],board[x-1] = board[x-1],board[x] if e == 'R' : board[x],board[x+1] = board[x+1],board[x] for i in range(y): print(' '.join(str(x) for x in board[i*y:i*y+y])) return #------------------------------------------
# 633xxxxx21 448 (2020-09-20 16:34) def print_moves(board, moves): # bonus function: optional b = [] for e in range(len(board)): b.append(str(board[e])) b = "".join(b) print("",b[0],b[1],b[2]) print("",b[3],b[4],b[5]) print("",b[6],b[7],b[8]) for i in range(len(moves)): z = board.index(0) if moves[i] == "U": board[z],board[z-3] = board[z-3],board[z] elif moves[i] == "D": board[z],board[z+3] = board[z+3],board[z] elif moves[i] == "L": board[z],board[z-1] = board[z-1],board[z] elif moves[i] == "R": board[z],board[z+1] = board[z+1],board[z] b = [] for e in range(len(board)): b.append(str(board[e])) b = "".join(b) print("---------",moves[i]) print("",b[0],b[1],b[2]) print("",b[3],b[4],b[5]) print("",b[6],b[7],b[8]) return #------------------------------------------
# 633xxxxx21 449 (2020-09-19 23:18) def print_moves(board, moves): # bonus function: optional def swap(list, pos1, pos2): list[pos1], list[pos2] = list[pos2], list[pos1] return list print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) for e in list(moves): print("---------",e) if board[0]==0 and e=="R": board=swap(board,1,0) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[0]==0 and e=="D": board=swap(board,3,0) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[8]==0 and e=="L": board=swap(board,8,7) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[8]==0 and e=="U": board=swap(board,8,5) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[7]==0 and e=="L": board=swap(board,7,6) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[7]==0 and e=="R": board=swap(board,7,8) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[7]==0 and e=="U": board=swap(board,7,4) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[6]==0 and e=="R": board=swap(board,6,7) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[6]==0 and e=="U": board=swap(board,6,3) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[5]==0 and e=="L": board=swap(board,5,4) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[5]==0 and e=="D": board=swap(board,5,8) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[5]==0 and e=="U": board=swap(board,5,2) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[5]==0 and e=="L": board=swap(board,5,4) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[3]==0 and e=="D": board=swap(board,3,6) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[3]==0 and e=="R": board=swap(board,3,4) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[3]==0 and e=="U": board=swap(board,3,0) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[2]==0 and e=="L": board=swap(board,1,2) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[2]==0 and e=="D": board=swap(board,2,5) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[1]==0 and e=="L": board=swap(board,1,0) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[1]==0 and e=="D": board=swap(board,1,4) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[1]==0 and e=="R": board=swap(board,1,2) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[4]==0 and e=="L": board=swap(board,3,4) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[4]==0 and e=="D": board=swap(board,7,4) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[4]==0 and e=="R": board=swap(board,4,5) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) elif board[4]==0 and e=="U": board=swap(board,1,4) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) return #------------------------------------------
# 633xxxxx21 450 (2020-09-20 14:23) def print_moves(board, moves): n=int(len(board)**(1/2)) for i in range(n): temp=[] for k in board[i*n:(i*n)+n]: temp.append(str(k)) print(" ".join(temp)) for ch in moves:# bonus function: optional j=board.index(0) if ch=="U": board[j],board[j-n]=board[j-n],board[j] elif ch=="D": board[j],board[j+n]=board[j+n],board[j] elif ch=="L": board[j],board[j-1]=board[j-1],board[j] elif ch=="R": board[j],board[j+1]=board[j+1],board[j] print("------",ch) for i in range(n): temp=[] for k in board[i*n:(i*n)+n]: temp.append(str(k)) print(" ".join(temp)) return #------------------------------------------
# 633xxxxx21 451 (2020-09-20 22:15) def print_moves(board, moves): return # ------------------------------------------
# 633xxxxx21 452 (2020-09-20 22:36) def print_moves(board, moves): # bonus function: optional for i in moves: a = board.index(0) ind = int(len(board)**0.5) if i == 'U': board[a] = board[a-ind] board[a-ind] = 0 if i == 'D': board[a] = board[a+ind] board[a+ind] = 0 if i == 'L': board[a] = board[a-1] board[a-1] = 0 if i == 'R': board[a] = board[a+1] board[a+1] = 0 print('----------',i) for j in range(0,len(board),ind): print(board[j:j+ind]) return #------------------------------------------
# 633xxxxx21 453 (2020-09-20 23:51) def print_moves(board, moves): # bonus function: optional return # ------------------------------------------
# 633xxxxx21 454 (2020-09-20 22:39) def print_moves(board, moves): n = int(len(board)**(1/2)) for e in range(n - 1, int(n**2), n): for d in range(e - (n - 1), e + 1): print(board[d], end = ' ') if e == d: print('') for e in range(len(moves)): print('------------',moves[e]) if moves[e] == 'U': pos_zero = board.index(0) board[pos_zero],board[pos_zero-n] = board[pos_zero-n],board[pos_zero] if moves[e] == 'D': pos_zero = board.index(0) board[pos_zero],board[pos_zero+n] = board[pos_zero+n],board[pos_zero] if moves[e] == 'L': pos_zero = board.index(0) board[pos_zero],board[pos_zero-1] = board[pos_zero-1],board[pos_zero] if moves[e] == 'R': pos_zero = board.index(0) board[pos_zero],board[pos_zero+1] = board[pos_zero+1],board[pos_zero] for e in range(n - 1, int(n**2), n): for d in range(e - (n - 1), e + 1): print(board[d], end = ' ') if e == d: print('') return #------------------------------------------
# 633xxxxx21 455 (2020-09-20 20:49) def print_moves(board, moves): # bonus function: optional N = int(len(board)**0.5) for i in range(0,(N*N)): A = "" if i%N == 0: for j in range(N): A += str(board[i])+" " i += 1 print(A) for c in moves : list = [] list = board i = list.index(0) if c =='U': x = list[i-N] list.pop(i) list.insert(i-N,0) list.pop(i-N-1) list.insert(i,x) elif c =='D' : x = list[i+N] list.pop(i) list.insert(i+N,0) list.pop(i+N-1) list.insert(i,x) elif c =='L' : list.pop(i) list.insert(i-1,0) elif c =='R' : list.pop(i) list.insert(i+1,0) print('--------- '+c) for i in range(0,N*N): A = "" if i%N == 0: for j in range(N): A += str(board[i])+ " " i += 1 print(A) return #------------------------------------------
# 633xxxxx21 456 (2020-09-20 19:19) def print_moves(board, moves): print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) for i in range(len(moves)): print('------------',moves[i]) if moves[i] == 'L': position_zero = board.index(0) board[position_zero],board[position_zero-1] = board[position_zero-1],board[position_zero] if moves[i] == 'R': position_zero = board.index(0) board[position_zero],board[position_zero+1] = board[position_zero+1],board[position_zero] if moves[i] == 'U': position_zero = board.index(0) board[position_zero],board[position_zero-3] = board[position_zero-3],board[position_zero] if moves[i] == 'D': position_zero = board.index(0) board[position_zero],board[position_zero+3] = board[position_zero+3],board[position_zero] print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) return #------------------------------------------
# 633xxxxx21 457 (2020-09-20 18:08) def print_moves(board, moves): # bonus function: optional n = len(board) N =2 while True: if(N**2==n): break N+=1 for i in(moves): m = board.index(0) if i == 'L': board[m] = board[m-1] board[m-1] = 0 elif i == 'D': board[m] = board[m+3] board[m+3] = 0 elif i =='R': board[m] = board[m+1] board[m+1] = 0 elif i =='U': board[m] = board[m-3] board[m-3] = 0 for j in(board): print(j,end=" ") if((board.index(j)+1)%N==0): print() print("--------- %s"%(i)) return #------------------------------------------
# 633xxxxx21 458 (2020-09-20 00:26) def print_moves(board, moves): # bonus function: optional print(" "+str(board[0])+" "+str(board[1])+" "+str(board[2])) print(" "+str(board[3])+" "+str(board[4])+" "+str(board[5])) print(" "+str(board[6])+" "+str(board[7])+" "+str(board[8])) for i in moves: print("-"*9,i) f=board.index(0) if i=="D": board[f],board[f+3]=board[f+3],board[f] elif i=="R": board[f], board[f+1] = board[f+1], board[f] elif i=="L": board[f],board[f-1]=board[f-1],board[f] elif i=="U": board[f], board[f-3] = board[f-3], board[f] print(" "+str(board[0])+" "+str(board[1])+" "+str(board[2])) print(" "+str(board[3])+" "+str(board[4])+" "+str(board[5])) print(" "+str(board[6])+" "+str(board[7])+" "+str(board[8])) return #------------------------------------------
# 633xxxxx21 459 (2020-09-20 23:13) def print_moves(board, moves): for i in range(0,len(board),3): s = [] for j in range(i,i+3): s.append(str(board[j])) print(" ".join(s)) for i in moves: if i == 'U': print('---------',i) x = board.index(0) board[x-3],board[x] = board[x],board[x-3] for i in range(0,len(board),3): s = [] for j in range(i,i+3): s.append(str(board[j])) print(" ".join(s)) if i == 'D': print('---------',i) x = board.index(0) board[x+3],board[x] = board[x],board[x+3] for i in range(0,len(board),3): s = [] for j in range(i,i+3): s.append(str(board[j])) print(" ".join(s)) if i == 'L': print('---------',i) x = board.index(0) board[x-1],board[x] = board[x],board[x-1] for i in range(0,len(board),3): s = [] for j in range(i,i+3): s.append(str(board[j])) print(" ".join(s)) if i == 'R': print('---------',i) x = board.index(0) board[x+1],board[x] = board[x],board[x+1] for i in range(0,len(board),3): s = [] for j in range(i,i+3): s.append(str(board[j])) print(" ".join(s)) return #------------------------------------------
# 633xxxxx21 460 (2020-09-20 23:08) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 461 (2020-09-20 23:59) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 462 (2020-09-20 15:32) def print_moves(board, moves): # bonus function: optional # ตารางที่แสดงจะขยายตามขนาดของPuzzle length = len(board) for i in range(1,length+1): if i*i == length: n = i break for c in moves: for i in range(len(board)): print(" "+str(board[i]), end=" "*((n-1)-len(str(board[i])))) if i % n == n-1: print() print("-"*n**2,c) index = board.index(0) if c == 'U': board[index-n], board[index] = board[index],board[index-n] elif c == 'D': board[index+n],board[index] = board[index],board[index+n] elif c == 'L': board[index-1],board[index] = board[index],board[index-1] elif c == 'R': board[index+1],board[index] = board[index],board[index+1] for i in range(len(board)): print(" " + str(board[i]), end=" "*((n-1)-len(str(board[i])))) if i % n == n-1: print() return #------------------------------------------
# 633xxxxx21 463 (2020-09-20 23:46) def print_moves(board, moves): def swap(board, p1, p2): board[p1], board[p2] = board[p2], board[p1] return board N = int(len(board)**0.5) for pos, num in enumerate(board): if num == 0: blank = pos for move in moves: if move == "U": swap(board, blank, blank + (-N)) blank += (-N) elif move == "D": swap(board, blank, blank + (N)) blank += (N) elif move == "L": swap(board, blank, blank + (-1)) blank += (-1) elif move == "R": swap(board, blank, blank + (1)) blank += (1) for i in range(N**2): print(board[i], " ", end = "") if (i+1) % N == 0: print("") print("---------", move) return None #------------------------------------------
# 633xxxxx21 464 (2020-09-19 10:24) def print_moves(board, moves): print() print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) for e in moves: if e == 'D': a = board.index(0) board[a],board[a+3] = board[a+3],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'L': a = board.index(0) board[a],board[a-1] = board[a-1],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'U': a = board.index(0) board[a],board[a-3] = board[a-3],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'R': a = board.index(0) board[a],board[a+1] = board[a+1],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) return #------------------------------------------
# 633xxxxx21 465 (2020-09-19 20:34) def print_moves(board,moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 466 (2020-09-20 23:26) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 467 (2020-09-19 19:42) def print_moves(board, moves): # bonus function: optional return # ------------------------------------------
# 633xxxxx21 468 (2020-09-20 03:37) def print_moves(board, moves): # bonus function: optional N = int((len(board))**(1/2)) def show(N,board,move): index = 0 show_board = '' for i in board: if index % N == 0: show_board += ' %s' %(i) elif index % N == N-1: show_board += ' %s\n' %(i) else: show_board += ' %s' %(i) index += 1 if move == 'First': print(show_board[:-1]) else: print('-'*(N*3) + move) print(show_board[:-1]) def up(N,board): newboard = list(board) locate_0 = board.index(0) x0 = locate_0 % N y0 = locate_0 // N xu = x0 yu = y0-1 locate_u = yu*N + xu newboard[locate_0], newboard[locate_u] = \ newboard[locate_u], newboard[locate_0] return newboard def down(N,board): newboard = list(board) locate_0 = board.index(0) x0 = locate_0 % N y0 = locate_0 // N xd = x0 yd = y0+1 locate_d = yd*N + xd newboard[locate_0], newboard[locate_d] = \ newboard[locate_d], newboard[locate_0] return newboard def left(N,board): newboard = list(board) locate_0 = board.index(0) x0 = locate_0 % N y0 = locate_0 // N xl = x0-1 yl = y0 locate_l = yl*N + xl newboard[locate_0], newboard[locate_l] = \ newboard[locate_l], newboard[locate_0] return newboard def right(N,board): newboard = list(board) locate_0 = board.index(0) x0 = locate_0 % N y0 = locate_0 // N xr = x0+1 yr = y0 locate_r = yr*N + xr newboard[locate_0], newboard[locate_r] = \ newboard[locate_r], newboard[locate_0] return newboard show(N,board,'First') for move in moves: if move == 'U': board = up(N,board) show(N,board,move) elif move == 'D': board = down(N,board) show(N,board,move) elif move == 'L': board = left(N,board) show(N,board,move) elif move == 'R': board = right(N,board) show(N,board,move) return #------------------------------------------
# 633xxxxx21 469 (2020-09-20 21:46) def print_moves(board, moves): # bonus function: optional x = len(board) N = int(math.sqrt(x)) for o in range(N) : for m in range(N) : print(board[(o*N)+m],end = " ") print() for i in moves : print('-'*(9)+i) k = board.index(0) if i == "U" : board[k],board[k-N] = board[k-N],board[k] if i == "D": board[k],board[k+N] = board[k+N],board[k] if i == "L": board[k],board[k-1] = board[k-1],board[k] if i == "R": board[k],board[k+1] = board[k+1],board[k] for o in range(N) : for m in range(N) : print(board[(o*N)+m],end = " ") print() return #------------------------------------------
# 633xxxxx21 470 (2020-09-16 19:42) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)): m = board.index(0) if moves[i] == "L": board[m],board[m-1] = board[m-1],board[m] print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) print("--------- L") elif moves[i] == "R": board[m],board[m+1] = board[m+1],board[m] print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) print("--------- R") elif moves[i] == "U": board[m],board[m-3] = board[m-3],board[m] print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) print("--------- U") elif moves[i] == "D": board[m],board[m+3] = board[m+3],board[m] print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) print("--------- D") return #------------------------------------------
# 633xxxxx21 471 (2020-09-20 15:48) def print_moves(board, moves): # bonus function: optional num = int((len(board))**0.5) t = '' for r in range(num): for ch in board[r*num+0:r*num+num]: t += str(ch) t+= ' ' print(t) t = '' i0 = board.index(0) for ch in moves: if ch == 'D': print('---------' ,ch) board[i0],board[i0+num] = board[i0+num],board[i0] elif ch == 'U': print('---------' ,ch) board[i0],board[i0-num] = board[i0-num],board[i0] elif ch == 'R': print('---------' ,ch) board[i0],board[i0+1] = board[i0+1],board[i0] elif ch == 'L': print('---------' ,ch) board[i0],board[i0-1] = board[i0-1],board[i0] i0 = board.index(0) for r in range(num): for ch in board[r*num+0:r*num+num]: t += str(ch) t+= ' ' print(t) t='' return #------------------------------------------
# 633xxxxx21 472 (2020-09-20 17:27) def print_moves(board, moves): pg = [str(e) for e in board] di = 1 while di**2 != len(board) : di += 1 for l in range(di): lin = ' ' for pos in range(di): lin += pg[di*l+pos]+' ' print(lin) for i in moves : print('---------',i) bp = pg.index('0') if i == 'U': pg.remove('0') p = pg.pop(bp-di) pg.insert(bp-di,'0') pg.insert(bp,p) if i == 'D': p = pg.pop(bp+di) pg.remove('0') pg.insert(bp,p) pg.insert(bp+di,'0') if i == 'L': pg.remove('0') pg.insert(bp-1,'0') if i == 'R': pg.remove('0') pg.insert(bp+1,'0') for l in range(di): lin = ' ' for pos in range(di): lin += pg[di*l+pos]+' ' print(lin) return #------------------------------------------
# 633xxxxx21 473 (2020-09-20 20:50) def print_moves(board, moves): # bonus function: optional # อยากทำเเต่ทำไม่ได้ค่ะ return #------------------------------------------
# 633xxxxx21 474 (2020-09-20 20:14) def print_moves(board, moves): # bonus function: optional ''' copy paste moveของเดิมเอามาเเก้บางอย่าง''' import math #หาN x N ว่า N=? N = int(math.sqrt(len(board)))#ไม่ต้องลบ1เหมือนอันเก่าเพราะไม่มี str move def move_up(board): U = list(board) #for create a new (copy)list for i in range(len(U)): #ไม่ต้องลบ1เหมือนอันเก่าเพราะไม่มี str move if U[i] == '0' : #เปลี่ยนเป็น string 0 เพราะจะใช้ .join() เเสดงผล U[i],U[i-N] = U[i-N],U[i] break return U def move_left(board): L = list(board) # for copy new list for i in range(len(L)): if L[i] == '0' : L[i],L[i-1] = L[i-1],L[i] break return L def move_right(board): R = list(board) # for copy new list for i in range(len(R)): if R[i] == '0' : R[i],R[i+1] = R[i+1], R[i] break return R def move_down(board): D = list(board) for i in range(len(D)): if D[i] == '0' : D[i],D[i+N] = D[i+N],D[i] break return D for i in range(len(board)): #เเปลง boardเป็นstr board[i] = str(board[i]) def print_form(): #เเสดงผลตามformที่บอก for i in range(0,N*N,N): print(' '.join(board[i:i+N])) print_form() for c in moves: if c == 'U': board = move_up(board) print('--------- U') print_form() elif c == 'L': board = move_left(board) print('--------- L') print_form() elif c == 'D': board = move_down(board) print('--------- D') print_form() elif c == 'R': board = move_right(board) print('--------- R') print_form() return #จบ #------------------------------------------
# 633xxxxx21 475 (2020-09-19 20:38) def print_moves(board, moves): # bonus function: optional N=int(len(board)**0.5) s=[[] for i in range(N)] n=int(len(board)**0.5) m=len(board) r=0 for i in range(0,m,n): for j in range(n): s[r].append(board[i+j]) r+=1 r,c=find0(s,N) for i in range(len(s)): row="" for j in range(len(s[i])): row+=str(s[i][j])+" " print(row.strip()) for e in moves: if e=="D": print("--------- D") s[r][c],s[r+1][c]=s[r+1][c],s[r][c] for i in range(len(s)): row="" for j in range(len(s[i])): row+=str(s[i][j])+" " print(row.strip()) r,c=find0(s,N) elif e=="L": print("--------- L") s[r][c],s[r][c-1]=s[r][c-1],s[r][c] for i in range(len(s)): row="" for j in range(len(s[i])): row+=str(s[i][j])+" " print(row.strip()) r,c=find0(s,N) elif e=="R": print("--------- R") s[r][c],s[r][c+1]=s[r][c+1],s[r][c] for i in range(len(s)): row="" for j in range(len(s[i])): row+=str(s[i][j])+" " print(row.strip()) r,c=find0(s,N) elif e=="U": print("--------- U") s[r][c],s[r-1][c]=s[r-1][c],s[r][c] for i in range(len(s)): row="" for j in range(len(s[i])): row+=str(s[i][j])+" " print(row.strip()) r,c=find0(s,N) return #------------------------------------------ def find0(s,N): for i in range(N): for j in range(N): if s[i][j]==0: r=i c=j return r,c
# 633xxxxx21 476 (2020-09-19 16:25) def print_moves(board, moves): # โบนัส (สีเหลือง) # bonus function: optional return #------------------------------------------
# 633xxxxx21 477 (2020-09-20 18:34) def print_moves (board, moves): # bonus function: optional pos = board.index(0) k=0 while k<len(board): for j in range(int(len(board)**0.5)): if j==int(len(board)**0.5)-1: print(board[j+k]) else: print(board[j+k],end=" ") k+=int(len(board)**0.5) a=int(len(board)**0.5) for i in range(len(moves)): pos = board.index(0) k=0 print("---------",moves[i]) if moves[i]=="R": board[pos],board[pos+1]=board[pos+1],board[pos] elif moves[i]=="L": board[pos],board[pos-1]=board[pos-1],board[pos] elif moves[i]=="U": board[pos],board[pos-a]=board[pos-a],board[pos] elif moves[i]=="D": board[pos],board[pos+a]=board[pos+a],board[pos] while k<len(board): for j in range(int(len(board)**0.5)): if j==int(len(board)**0.5)-1: print(board[j+k]) else: print(board[j+k],end=" ") k+=int(len(board)**0.5) return # ------------------------------------------
# 633xxxxx21 478 (2020-09-20 19:22) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 479 (2020-09-20 00:40) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 480 (2020-09-19 20:11) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 481 (2020-09-19 21:55) def print_moves(board, moves): print(board[0],' ',board[1],' ',board[2]) print(board[3],' ',board[4],' ',board[5]) print(board[6],' ',board[7],' ',board[8]) for j in range(len(moves)): print("----------",moves[j]) if moves[j] == 'U': k = board.index(0) board[k],board[k-3] = board[k-3],board[k] elif moves[j] == 'D': k = board.index(0) board[k],board[k+3] = board[k+3],board[k] elif moves[j] == 'L': k = board.index(0) board[k-1],board[k] = board[k],board[k-1] elif moves[j] == 'R': k = board.index(0) board[k],board[k+1] = board[k+1],board[k] print(board[0],' ',board[1],' ',board[2]) print(board[3],' ',board[4],' ',board[5]) print(board[6],' ',board[7],' ',board[8]) return #------------------------------------------
# 633xxxxx21 482 (2020-09-20 22:45) def print_moves(board, moves): import math # bonus function: optional blank = board.index(0) node = board n = int(math.sqrt((len(node)-1))) print(node[0], node[1], node[2]) print(node[3], node[4], node[5]) print(node[6], node[7], node[8]) for m in moves: if (m == 'U'): if blank not in range(0,n): node[blank], node[blank-3] = node[blank-3], node[blank] blank = node.index(0) elif (m == 'D'): if blank not in range(n**2-n, n**2-1): node[blank], node[blank+3] = node[blank+3], node[blank] blank = node.index(0) elif (m == 'R'): if blank not in range((n-2)*n-1, n**2-1, n): node[blank], node[blank+1] = node[blank+1], node[blank] blank = node.index(0) elif (m == 'L'): if blank not in range(0, n**2-n, n): node[blank], node[blank-1] = node[blank-1], node[blank] blank = node.index(0) print("--------- "+m) print(node[0], node[1], node[2]) print(node[3], node[4], node[5]) print(node[6], node[7], node[8]) return #------------------------------------------
# 633xxxxx21 483 (2020-09-20 19:24) def print_moves(board, moves): p = board.index(0) S = len(board) #size**2 s = int(S**0.5) #size #a = แถว #b = หลัก for a in range(s): for b in range(s): print(board[a*3+b],end=' ') print('') for t in range(len(moves)): p = board.index(0) print('---------'+ moves[t]) if moves[t] == 'L': board[p],board[p-1] = board[p-1],board[p] elif moves[t] == 'R': board[p],board[p+1] = board[p+1],board[p] elif moves[t] == 'U': board[p],board[p-s] = board[p-s],board[p] elif moves[t] == 'D' : board[p],board[p+s] = board[p+s],board[p] for a in range(s): for b in range(s): print(board[a*3+b],end=' ') print('') return #------------------------------------------
# 633xxxxx21 484 (2020-09-20 21:46) def print_moves(board, moves): # bonus function: optional n = int(math.sqrt(len(board))) x = board[:] for i in range(n): for j in range(n): print(x[j+i*n],end = ' ') print() for i in moves: print('-'*(n**2-n) + i) z = x.index(0) if i == 'L': x[z],x[z-1] = x[z-1],x[z] if i == 'R': x[z],x[z+1] = x[z+1],x[z] if i == 'U': x[z],x[z-n] = x[z-n],x[z] if i == 'D': x[z],x[z+n] = x[z+n],x[z] for i in range(n): for j in range(n): print(x[j+i*n],end = ' ') print() return #------------------------------------------
# 633xxxxx21 485 (2020-09-20 23:43) def print_moves(board, moves): # bonus function: optional print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) board_loop = board for j in moves: for k in board_loop: if k == 0: ind = board_loop.index(0) if j == 'U': board[ind-3],board[ind] = board[ind],board[ind-3] break elif j == 'L': board[ind-1],board[ind] = board[ind],board[ind-1] break elif j == 'R': board[ind+1],board[ind] = board[ind],board[ind+1] break elif j == 'D': board[ind+3],board[ind] = board[ind],board[ind+3] break print("---------",j) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) board_loop = board return #------------------------------------------
# 633xxxxx21 486 (2020-09-20 23:31) def print_moves(board, moves): # bonus function: optional a = board.index(0) k = board print(k[0], k[1], k[2]) print(k[3], k[4], k[5]) print(k[6], k[7], k[8]) for m in moves: if (m == "U"): if not(a in [0,1,2]): k[a], k[a-3] = k[a-3], k[a] a = k.index(0) elif (m == "D"): if not(a in [6,7,8]): k[a], k[a+3] = k[a+3], k[a] a = k.index(0) elif (m == "R"): if not(a in [2,5,8]): k[a], k[a+1] = k[a+1], k[a] a = k.index(0) elif (m == "L"): if (not a in [0,3,6]): k[a], k[a-1] = k[a-1], k[a] a = k.index(0) print("--------- "+m) print(k[0], k[1], k[2]) print(k[3], k[4], k[5]) print(k[6], k[7], k[8]) return #------------------------------------------
# 633xxxxx21 487 (2020-09-20 12:19) def print_moves(board, moves): print() print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) for e in moves: if e == 'D': a = board.index(0) board[a],board[a+3] = board[a+3],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'L': a = board.index(0) board[a],board[a-1] = board[a-1],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'U': a = board.index(0) board[a],board[a-3] = board[a-3],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'R': a = board.index(0) board[a],board[a+1] = board[a+1],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) return #------------------------------------------
# 633xxxxx21 488 (2020-09-20 23:36) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 489 (2020-09-20 23:43) def print_moves(board, moves): n = (len(board)) ** (1 / 2) n = int(n) pos = board.index(0) for i in range(n): x = board[n * i:n * (i + 1)] x = map(str, x) print(' '.join(x)) for j in moves: print('--------------', j) if j == 'U': board[pos], board[pos - n] = board[pos - n], board[pos] elif j == 'D': board[pos], board[pos + n] = board[pos + n], board[pos] elif j == 'L': board[pos], board[pos - 1] = board[pos - 1], board[pos] elif j == 'R': board[pos], board[pos + 1] = board[pos + 1], board[pos] pos = board.index(0) for i in range(n): x = board[n * i:n * (i + 1)] x = map(str, x) print(' '.join(x)) return # ------------------------------------------
# 633xxxxx21 490 (2020-09-20 22:48) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 491 (2020-09-20 23:44) def print_moves(board, moves): # bonus function: optional N = int(math.sqrt(len(board))) tboard = list(board) print_board(board) for i in range(len(moves)): z = tboard.index(0) if moves[i]=='U' : tboard[z-N],tboard[z] = tboard[z],tboard[z-N] elif moves[i]=='D' : tboard[z+N],tboard[z] = tboard[z],tboard[z+N] elif moves[i]=='L' : tboard[z-1],tboard[z] = tboard[z],tboard[z-1] elif moves[i]=='R' : tboard[z+1],tboard[z] = tboard[z],tboard[z+1] print('---------',moves[i]) print_board(tboard) return def print_board(board): N = int(math.sqrt(len(board))) for i in range(1,len(board)+1) : print(str(board[i-1])+' ',end='') if i%N==0:print('\n') #------------------------------------------
# 633xxxxx21 492 (2020-09-20 22:49) def print_moves(board, moves): # return #------------------------------------------
# 633xxxxx21 493 (2020-09-20 21:11) def print_moves(board, moves): N = len(board) n = int(N**0.5) pl = board.index(0) for k in range(N): print(board[k],end=' ') if (k+1)%(N**0.5) == 0: print() for i in range(len(moves)): print('---------',moves[i]) pl = board.index(0) if moves[i] == 'L': board[pl],board[pl-1] = board[pl-1],board[pl] #สลับซ้าย elif moves[i] == 'U': board[pl],board[pl-n] = board[pl-n],board[pl] #สลับบน elif moves[i] == 'D': board[pl],board[pl+n] = board[pl+n],board[pl] #สลับล่าง elif moves[i] == 'R': board[pl],board[pl+1] = board[pl+1],board[pl] #สลับขวา for m in range(N): print(board[m],end=' ') if (m+1)%(N**0.5) == 0: print() return #------------------------------------------
# 633xxxxx21 494 (2020-09-20 23:46) def print_moves(board, moves): return #------------------------------------------
# 633xxxxx21 495 (2020-09-20 21:38) def print_moves(board, moves): x=len(board) y=board.index(0) k=int(x**0.5) for i in range(k): for z in range(k): print(board[i*3+z],end='') print("") for a in range(len(moves)): y=board.index(0) print('---------'+ moves[a]) if moves[a]=='U': board[y],board[y-k]=board[y-k],board[y] elif moves[a]=='D': board[y],board[y+k]=board[y+k],board[y] elif moves[a]=='L': board[y],board[y-1]=board[y-1],board[y] elif moves[a]=='R': board[y],board[y+1]=board[y+1],board[y] for i in range(k): for z in range(k): print(board[i*3+z],end='') print("") return #------------------------------------------
# 633xxxxx21 496 (2020-09-20 14:26) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 497 (2020-09-20 21:37) def print_moves(board, moves): x=len(board) y=board.index(0) n=int(x**(1/2)) for i in range(n): for z in range(n): print(board[i*3+z],end='') print("") for a in range(len(moves)): y=board.index(0) print('---------'+ moves[a]) if moves[a]=='U': board[y],board[y-n]=board[y-n],board[y] elif moves[a]=='D': board[y],board[y+n]=board[y+n],board[y] elif moves[a]=='L': board[y],board[y-1]=board[y-1],board[y] elif moves[a]=='R': board[y],board[y+1]=board[y+1],board[y] for i in range(n): for z in range(n): print(board[i*3+z],end='') print("") return #------------------------------------------
# 633xxxxx21 498 (2020-09-20 19:03) def print_moves(board, moves): # bonus function: optional B=board.index(0) for x in range(9): print(board[x],end=' ') if (x+1) in [3,6,9]: print() for y in range(len(moves)): print('---------',moves[y]) B=board.index(0) if moves[y]=='U': board[B],board[B-3]=board[B-3],board[B] elif moves[y]=='D': board[B],board[B+3]=board[B+3],board[B] elif moves[y]=='L': board[B],board[B-1]=board[B-1],board[B] elif moves[y]=='R': board[B],board[B+1]=board[B+1],board[B] for z in range(9): print(board[z],end=' ') if (z+1) in [3,6,9]: print() return #------------------------------------------
# 633xxxxx21 499 (2020-09-19 17:41) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)): pin=board.index(0) k=0 sqr=pow(len(board),0.5) sqr=int(sqr) if moves[i]=='U': board[pin],board[pin-sqr]=board[pin-sqr],board[pin] elif moves[i]=='D': board[pin],board[pin+sqr]=board[pin+sqr],board[pin] elif moves[i]=='L': board[pin],board[pin-1]=board[pin-1],board[pin] elif moves[i]=='R': board[pin],board[pin+1]=board[pin+1],board[pin] for e in range(len(board)): print(str(board[e])+" ",end="") k+=1 if (k)%sqr==0: print("") print("------------------"+moves[i]) return #------------------------------------------
# 633xxxxx21 500 (2020-09-18 22:32) def print_moves(board, moves): # bonus function: optional order_move = moves[:] #ค่อยเปลี่ยน order_move เป็น order_move ด้วยfunction'command+f' play_puzzle = board[:]#ค่อยเปลี่ยน play_puzzle เป็น play_puzzle ด้วยfunction'command+f' zero_index = board.index(0) z = zero_index for e in range(0,len(board)-2,3): print(board[e],board[e+1],board[e+2]) for i in range(len(order_move)): if order_move[i] == 'D': print('---------'+order_move[i]) play_puzzle[z],play_puzzle[z+3] = play_puzzle[z+3],play_puzzle[z] z = play_puzzle.index(0) for e in range(0,len(play_puzzle)-2,3): print(play_puzzle[e],play_puzzle[e+1],play_puzzle[e+2]) elif order_move[i] == 'U': print('---------'+order_move[i]) play_puzzle[z],play_puzzle[z-3] = play_puzzle[z-3],play_puzzle[z] z = play_puzzle.index(0) for e in range(0,len(play_puzzle)-2,3): print(play_puzzle[e],play_puzzle[e+1],play_puzzle[e+2]) elif order_move[i] == 'R': print('---------'+order_move[i]) play_puzzle[z],play_puzzle[z+1] = play_puzzle[z+1],play_puzzle[z] z = play_puzzle.index(0) for e in range(0,len(play_puzzle)-2,3): print(play_puzzle[e],play_puzzle[e+1],play_puzzle[e+2]) elif order_move[i] == 'L': print('---------'+order_move[i]) play_puzzle[z],play_puzzle[z-1] = play_puzzle[z-1],play_puzzle[z] z = play_puzzle.index(0) for e in range(0,len(play_puzzle)-2,3): print(play_puzzle[e],play_puzzle[e+1],play_puzzle[e+2]) return #------------------------------------------
# 633xxxxx21 501 (2020-09-20 22:23) def print_moves(board, moves): # bonus function: optional board1=list(board) ans=[] com="" for i in range(len(moves)) : r=board.index(0) if moves[i] == "R" : R=list(board) R[r],R[r+1]=R[r+1],R[r] ans.append(R) board=list(R) elif moves[i] == "L" : L=list(board) L[r],L[r-1]=L[r-1],L[r] ans.append(L) board=list(L) elif moves[i] == "U" : U=list(board) U[r],U[r-3]=U[r-3],U[r] ans.append(U) board=list(U) elif moves[i] == "D" : D=list(board) D[r],D[r+3]=D[r+3],D[r] ans.append(D) board=list(D) com+=moves[i] for i in range(0,9,3) : print(" "+str(board1[i])+" "+str(board1[i+1])+" "+str(board1[i+2])) for i in range(len(ans)) : print("-"*9+" "+com[i]) for e in range(0,9,3) : print(" "+str(ans[i][e])+" "+str(ans[i][e+1])+" "+str(ans[i][e+2])) return #------------------------------------------
# 633xxxxx21 502 (2020-09-20 23:23) def print_moves(board, moves): # bonus function: optional print() print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) for e in moves: if e == 'D': a = board.index(0) board[a],board[a+3] = board[a+3],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'L': a = board.index(0) board[a],board[a-1] = board[a-1],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'U': a = board.index(0) board[a],board[a-3] = board[a-3],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'R': a = board.index(0) board[a],board[a+1] = board[a+1],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) return #------------------------------------------
# 633xxxxx21 503 (2020-09-20 14:33) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 504 (2020-09-20 22:52) def print_moves(board, moves):# bonus function: optional for i in range(len(moves)): print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print('---------',moves[i]) k = board.index(0) if moves[i] == 'U': board.remove(0) board.insert(k-3,0) board.insert(k+1,board[k-2]) board.pop(k-2) elif moves[i] == 'D': board.remove(0) board.insert(k+2,0) board.insert(k,board[k+3]) board.pop(k+4) elif moves[i] == 'R': board.remove(0) board.insert(k+1,0) elif moves[i] == 'L': board.remove(0) board.insert(k-1,0) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 505 (2020-09-20 21:46) def print_moves(board, moves): # bonus function: optional # bonus 3*3------------------------------------------------------------------ if len(board) == 9 : blank = board.index(0) node = board print(node[0], node[1], node[2]) print(node[3], node[4], node[5]) print(node[6], node[7], node[8]) for m in moves: if m == 'U': node[blank], node[blank-3] = node[blank-3], node[blank] blank = node.index(0) elif m == 'D': node[blank], node[blank+3] = node[blank+3], node[blank] blank = node.index(0) elif (m == 'R'): node[blank], node[blank+1] = node[blank+1], node[blank] blank = node.index(0) elif (m == 'L'): node[blank], node[blank-1] = node[blank-1], node[blank] blank = node.index(0) print("--------- "+m) print(node[0], node[1], node[2]) print(node[3], node[4], node[5]) print(node[6], node[7], node[8]) # bonus 4*4------------------------------------------------------------------ elif len(board) == 16 : blank = board.index(0) node = board print(node[0],node[1],node[2],node[3]) print(node[4],node[5],node[6],node[7]) print(node[8],node[9],node[10],node[11]) print(node[12],node[13],node[14],node[15]) for m in moves: if m == 'U': node[blank], node[blank-4] = node[blank-4], node[blank] blank = node.index(0) elif m == 'D': node[blank], node[blank+4] = node[blank+4], node[blank] blank = node.index(0) elif (m == 'R'): node[blank], node[blank+1] = node[blank+1], node[blank] blank = node.index(0) elif (m == 'L'): node[blank], node[blank-1] = node[blank-1], node[blank] blank = node.index(0) print("--------- "+m) print(node[0],node[1],node[2],node[3]) print(node[4],node[5],node[6],node[7]) print(node[8],node[9],node[10],node[11]) print(node[12],node[13],node[14],node[15]) return #------------------------------------------
# 633xxxxx21 506 (2020-09-20 21:24) def print_moves(board, moves): # bonus function: optional w = board.index(0) t = int(math.sqrt(len(board))) print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) for m in moves: if m == "R": if w%t != t-1: board[w],board[w+1] = board[w+1],board[w] w = board.index(0) if m == "U": if w-t>=0: board[w],board[w-t] = board[w-t],board[w] w = board.index(0) if m == "L": if w%t != 0: board[w],board[w-1] = board[w-1],board[w] w = board.index(0) if m == "D": if w<(t*(t-1)): board[w],board[w+t] = board[w+t],board[w] w = board.index(0) print("--------- "+m) print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) return #------------------------------------------
# 633xxxxx21 507 (2020-09-20 15:18) def print_moves(board, moves): return #------------------------------------------
# 633xxxxx21 508 (2020-09-20 22:27) def print_moves(board, moves): # bonus function: optional blank = board.index(0) node = board print(node[0], node[1], node[2]) print(node[3], node[4], node[5]) print(node[6], node[7], node[8]) for m in moves: if (m == 'U'): if blank in [3,4,5,6,7,8]: node[blank], node[blank-3] = node[blank-3], node[blank] blank = node.index(0) elif (m == 'D'): if blank in [0,1,2,3,4,5] : node[blank], node[blank+3] = node[blank+3], node[blank] blank = node.index(0) elif (m == 'R'): if blank in [0,1,3,4,6,7]: node[blank], node[blank+1] = node[blank+1], node[blank] blank = node.index(0) elif (m == 'L'): if blank in [1,2,4,5,7,8]: node[blank], node[blank-1] = node[blank-1], node[blank] blank = node.index(0) print("--------- "+m) print(node[0], node[1], node[2]) print(node[3], node[4], node[5]) print(node[6], node[7], node[8]) return #------------------------------------------
# 633xxxxx21 509 (2020-09-20 21:05) def print_moves(board, moves): A = len(board) a = int(sqrt(A)) B = board.index(0) #w = แถว #h = หลัก for w in range(a): for h in range(a): print(board[w*3+h],end=' ') print('') for t in range(len(moves)): B = board.index(0) print('--------'+ moves[t]) if moves[t] == 'U': board[B],board[B-a] = board[B-a],board[B] elif moves[t] == 'D': board[B],board[B+a] = board[B+a],board[B] elif moves[t] == 'L': board[B],board[B-1] = board[B-1],board[B] else: board[B],board[B+1] = board[B+1],board[B] for w in range(a): for h in range(a): print(board[w*3+h],end=' ') print('') return #------------------------------------------
# 633xxxxx21 510 (2020-09-19 16:08) def print_moves(board, moves): # bonus function: optional for e in moves: print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) vac = board.index(0) if e == "L": board[vac],board[vac-1] = board[vac-1],board[vac] print("--------- L") elif e == "R": board[vac],board[vac+1] = board[vac+1],board[vac] print("--------- R") elif e == "U": board[vac],board[vac-3] = board[vac-3],board[vac] print("--------- U") elif e == "D": board[vac],board[vac+3] = board[vac+3],board[vac] print("--------- D") print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) return #------------------------------------------
# 633xxxxx21 511 (2020-09-20 15:35) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 512 (2020-09-20 22:16) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)): print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print('---------',moves[i]) u = board.index(0) if moves[i] == 'U': board.remove(0) board.insert(u-3,0) board.insert(u+1,board[u-2]) board.pop(u-2) elif moves[i] == 'D': board.remove(0) board.insert(u+2,0) board.insert(u,board[u+3]) board.pop(u+4) elif moves[i] == 'R': board.remove(0) board.insert(u+1,0) elif moves[i] == 'L': board.remove(0) board.insert(u-1,0) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 513 (2020-09-20 22:27) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 514 (2020-09-20 20:00) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 515 (2020-09-20 22:43) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 516 (2020-09-20 21:13) def print_moves(board, moves): for i in range(int(math.sqrt(len(board)))): pboard = [] for j in range(int(math.sqrt(len(board)))): pboard.append(board[3*i+j]) print(*pboard,sep = ' ') print('') for a in range(len(moves)): print('--------'+moves[a]) if moves[a]=='U': zero = board.index(0) board[zero],board[zero-3]=board[zero-3],board[zero] elif moves[a]=='D': zero = board.index(0) board[zero],board[zero+3]=board[zero+3],board[zero] elif moves[a]=='L': zero = board.index(0) board[zero],board[zero-1]=board[zero-1],board[zero] elif moves[a]=='R': zero = board.index(0) board[zero],board[zero+1]=board[zero+1],board[zero] for i in range(int(math.sqrt(len(board)))): pboard = [] for j in range(int(math.sqrt(len(board)))): pboard.append(board[3*i+j]) print(*pboard,sep =' ') print('') return #------------------------------------------
# 633xxxxx21 517 (2020-09-20 20:55) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 518 (2020-09-20 22:14) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 519 (2020-09-20 22:44) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 520 (2020-09-20 23:52) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 521 (2020-09-20 22:24) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 522 (2020-09-20 12:04) def print_moves(board, moves): A = len(board) a = int(A**(1/2)) B = board.index(0) for i in range(0,A): print(board[i],end='') if (i+1)%(A**(1/2)) == 0: print() for i in range(0,len(moves)): print('---------',moves[i]) B = board.index(0) if moves[i] == 'L': board[B],board[B-1] = board[B-1],board[B] elif moves[i] == 'U': board[B],board[B-a] = board[B-a],board[B] elif moves[i] == 'D': board[B],board[B+a] = board[B+a],board[B] else : board[B],board[B+1] = board[B+1],board[B] for j in range(0,A): print(board[j],end='') if (j+1)%(A**(1/2)) == 0: print() return #------------------------------------------
# 633xxxxx21 523 (2020-09-20 22:53) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 524 (2020-09-20 18:37) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 525 (2020-09-18 16:44) def print_moves(board, moves): # bonus function: optional N=int(len(board)**0.5) def s(l,a,b): l[a],l[b]=l[b],l[a] return l for i in range(N): print(" ".join(str(i) for i in board[N*i:N*i+N])) for move in moves: print("---------"+move) a=board.index(0) node=board if move=="L":s(node,a-1,a) if move=="R":s(node,a+1,a) if move=="U":s(node,a-N,a) if move=="D":s(node,a+N,a) board=node for i in range(N): print(" ".join(str(i) for i in board[N*i:N*i+N])) return #------------------------------------------
# 633xxxxx21 526 (2020-09-19 23:23) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 527 (2020-09-20 21:48) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 528 (2020-09-20 23:38) def print_moves(board, moves): # bonus function: optional b = board.index(0) x = board p = len(board) s = int(p**(1/2)) print(x[0], x[1], x[2]) print(x[3], x[4], x[5]) print(x[6], x[7], x[8]) for m in moves: if (m == 'U'): if b > s-1: x[b], x[b-s] = x[b-s], x[b] b = x.index(0) elif (m == 'D'): if 0<=b<s*(s-1): x[b], x[b+s] = x[b+s], x[b] b = x.index(0) elif (m == 'R'): if b % s != s-1: x[b], x[b+1] = x[b+1], x[b] b = x.index(0) elif (m == 'L'): if b % s != 0: x[b], x[b-1] = x[b-1], x[b] b = x.index(0) print("--------- "+m) print(x[0], x[1], x[2]) print(x[3], x[4], x[5]) print(x[6], x[7], x[8]) return #------------------------------------------
# 633xxxxx21 529 (2020-09-20 23:47) def print_moves(board, moves): b = len(moves) # c = board.index(0) for j in range(len(board)): print(board[j],end=" ") if (j+1)%3 == 0 : print() for i in range(len(moves)): c = board.index(0) if moves[i] == "R": board[c],board[c+1] = board[c+1],board[c] elif moves[i] == "L": board[c],board[c-1] = board[c-1],board[c] elif moves[i] == "U": board[c],board[c-3] = board[c-3],board[c] elif moves[i] == "D": board[c],board[c+3] = board[c+3],board[c] print("---------",moves[i]) for j in range(len(board)): print(board[j],end=" ") if (j+1)%3 == 0 : print() # bonus function: optional return #------------------------------------------
# 633xxxxx21 530 (2020-09-20 13:51) def print_moves(board, moves): # bonus function: optional for e in moves: print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) x = board.index(0) if e == "D": #Down+3 board[x] , board[x+3] = board[x+3] , board[x] print("--------- D") elif e =="U": #Up -3 board[x] , board[x-3] = board[x-3] , board[x] print("--------- U") elif e == "L": #Left-1 board[x] , board[x-1] = board[x-1] , board[x] print("--------- L") elif e == "R": #Right+1 board[x] , board[x+1] = board[x+1] , board[x] print("--------- R") print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) return #------------------------------------------
# 633xxxxx21 531 (2020-09-20 22:59) def print_moves(board, moves): return # ------------------------------------------
# 633xxxxx21 532 (2020-09-20 23:10) def print_moves(board, moves): # bonus function: optional for e in range(0, 9,3): print(str(board[e])+' '+ str(board[e+1])+' '+ str(board[e+2])) boardx = list(board) for i in range(0, len(moves)): if moves[i] == 'U': g = board.index(0) if 0 <= g <= 2: pass else: x = boardx.pop(g-3) y = boardx.pop(g-1) boardx.insert(g-3, y) boardx.insert(g, x) print('-'*9 + ' U') for e in range(0, 9,3): print(str(boardx[e])+' '+ str(boardx[e+1])+' '+ str(boardx[e+2])) elif moves[i] == 'R': g = board.index(0) if g in range(2, 9, 3): pass else: boardx = list(board) x = boardx.pop(g+1) y = boardx.pop(g) boardx.insert(g, y) boardx.insert(g, x) print('-'*9 + ' R') for e in range(0, 9,3): print(str(boardx[e])+' '+ str(boardx[e+1])+' '+ str(boardx[e+2])) elif moves[i] == 'D': g = board.index(0) if g in range(6,9): pass else: x = boardx.pop(g+3) y = boardx.pop(g) boardx.insert(g+2, y) boardx.insert(g, x) print('-'*9 + ' D') for e in range(0, 9,3): print(str(boardx[e])+' '+ str(boardx[e+1])+' '+ str(boardx[e+2])) elif moves[i] == 'L': g = board.index(0) if g in range(0,8,3): pass else: boardx = list(board) x = boardx.pop(g-1) y = boardx.pop(g-1) boardx.insert(g-1, y) boardx.insert(g, x) print('-'*9 + ' L') for e in range(0, 9,3): print(str(boardx[e])+' '+ str(boardx[e+1])+' '+ str(boardx[e+2])) board = boardx return #------------------------------------------
# 633xxxxx21 533 (2020-09-20 23:46) def print_moves(board, moves): # bonus function: optional N = int(len(board)**0.5) copyB = board.copy() for i in ' '+moves: mv = 0 if i != ' ': print('-------',i) if i == 'D': mv = N if i == 'U': mv = -N if i == 'R': mv = 1 if i == 'L': mv = -1 a = copyB.index(0) copyB[a], copyB[a+mv] = copyB[a+mv], copyB[a] for j in range(N): pr = [str(e) for e in copyB[j*N:j*N+N]] print(' ',end = '') print(' '.join(pr)+' ') return #------------------------------------------
# 633xxxxx21 534 (2020-09-20 20:39) def print_moves(board, moves): # bonus function: optional order = int((len(board))**0.5) p = '' for r in range(order): for ch in board[r*order+0:r*order+order]: p += str(ch) p+= ' ' print(p) p = '' d0 = board.index(0) for ch in moves: if ch == 'D': print('---------' ,ch) board[d0],board[d0+order] = board[d0+order],board[d0] elif ch == 'U': print('---------' ,ch) board[d0],board[d0-order] = board[d0-order],board[d0] elif ch == 'R': print('---------' ,ch) board[d0],board[d0+1] = board[d0+1],board[d0] elif ch == 'L': print('---------' ,ch) board[d0],board[d0-1] = board[d0-1],board[d0] d0 = board.index(0) for r in range(order): for ch in board[r*order+0:r*order+order]: p += str(ch) p+= ' ' print(p) p='' return #------------------------------------------
# 633xxxxx21 535 (2020-09-19 21:32) def print_moves(board, moves): for i in moves: a=board.index(0) if i =='R': board[a+1],board[a]= board[a],board[a+1] elif i =='L': board[a-1],board[a]= board[a],board[a-1] elif i =='D': board[a],board[a+m]= board[a+m],board[a] elif i =='U': board[a],board[a-m]= board[a-m],board[a] for j in range(m): u='' for k in range(m): u+=str(board[(m*j)+k]) print(u) #print(board[(m*j)],board[(m*j)+1],board[(m*j)+2]) print('---------',i) return #------------------------------------------
# 633xxxxx21 536 (2020-09-20 23:39) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 537 (2020-09-20 21:07) def print_moves(board, moves): print_3x(board) for i in range(len(moves)): zero = board.index(0) m = moves[i] if m == 'U': board[zero],board[zero-3] = board[zero-3],board[zero] elif m == 'D': board[zero],board[zero+3] = board[zero+3],board[zero] elif m == 'L': board[zero],board[zero-1] = board[zero-1],board[zero] elif m == 'R': board[zero],board[zero+1] = board[zero+1],board[zero] print('---------',m) print_3x(board) return #------------------------------------------ def print_3x(board): for x in range(3): print(board[x*3], board[(x*3)+1], board[(x*3)+2]) #------------------------------------------
# 633xxxxx21 538 (2020-09-18 22:40) def print_moves(board, moves): # bonus function: optional N=int(len(board)**(0.5)) for i in range(N): ja='' for j in range(N): ja+=" "+str(board[i*N+j])+" " print(ja) for b in moves: tum=board.index(0) if b=='U': board[tum],board[tum-N]=board[tum-N],board[tum] elif b=='D': board[tum],board[tum+N]=board[tum+N],board[tum] elif b=='L': board[tum],board[tum-1]=board[tum-1],board[tum] elif b=='R': board[tum],board[tum+1]=board[tum+1],board[tum] print("---"*N,b) for i in range(N): ja='' for j in range(N): ja+=" "+str(board[i*N+j])+" " print(ja) return #------------------------------------------
# 633xxxxx21 539 (2020-09-20 18:06) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 540 (2020-09-20 18:33) def print_moves(board, moves): # bonus function: optional from math import sqrt N = int(sqrt(len(board))) m = {'D':N,'U':-N,'R':1,'L':-1,' ':0} pboard = board.copy() for i in ' '+moves: if i != ' ': print('---------',i) spPos = pboard.index(0) pboard[spPos], pboard[spPos+m[i]] = pboard[spPos+m[i]], pboard[spPos] for j in range(N): b = j*N line = [str(e) for e in pboard[b:b+N]] print(' '+' '.join(line)+' ') return #------------------------------------------
# 633xxxxx21 541 (2020-09-20 22:46) def print_moves(board, moves): print() print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) for e in moves: if e == 'D': a = board.index(0) board[a],board[a+3] = board[a+3],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'L': a = board.index(0) board[a],board[a-1] = board[a-1],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'U': a = board.index(0) board[a],board[a-3] = board[a-3],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'R': a = board.index(0) board[a],board[a+1] = board[a+1],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) return #------------------------------------------
# 633xxxxx21 542 (2020-09-20 23:59) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 543 (2020-09-20 22:40) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 544 (2020-09-20 21:25) def print_moves(board, moves):# bonus function: optional return #------------------------------------------
# 633xxxxx21 545 (2020-09-20 20:42) def print_moves(board, moves): boards=[str(i) for i in board] x=boards[:] for i in range(0,7,3): print(" "+" ".join(boards[i:i+3])) print("--------- "+moves[0]) z=1 for i in moves: a=boards.index("0") if i=="U": boards[a],boards[a-3]=boards[a-3],boards[a] elif i=="R": boards[a],boards[a+1]=boards[a+1],boards[a] elif i=="L": boards[a],boards[a-1]=boards[a-1],boards[a] elif i=="D": boards[a],boards[a+3]=boards[a+3],boards[a] for k in range(0,7,3): print(" "+" ".join(boards[k:k+3])) if z!=len(moves) : print("--------- "+moves[z]) z+=1 return '' #------------------------------------------
# 633xxxxx21 546 (2020-09-19 19:18) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 547 (2020-09-20 14:04) def print_moves(board, moves): n = int(len(board)**0.5) def print_board(board): n = int(len(board)**0.5) for i in range(n): line = "" for j in range(n): index = i*n if n <= 3: line += str(board[index + j]) + " " else: line += "{:>2}".format(str(board[index + j])) + " " print(line) # bonus function: optional print_board(board) #print(board[0],' ',board[1],' ',board[2]) #print(board[3],' ',board[4],' ',board[5]) #print(board[6],' ',board[7],' ',board[8]) for m in moves: #print(m) #print(board.index(0)) #print(board[board.index(0)]) if m =='D': a = board.index(0) b = board.index(0)+n board[a],board[b] = board[b],board[a] #board[board.index(0)], board[board.index(0)+3] = board[board.index(0)+3], board[board.index(0)] if m =='U': a = board.index(0) b = board.index(0)-n board[a],board[b] = board[b],board[a] #board[board.index(0)], board[int(board.index(0))-3] = board[int(board.index(0))-3], board[board.index(0)] if m =='L': a = board.index(0) b = board.index(0)-1 board[a],board[b] = board[b],board[a] #board[board.index(0)], board[board.index(0)-1] = board[board.index(0)-1], board[board.index(0)] if m =='R': a = board.index(0) b = board.index(0)+1 board[a],board[b] = board[b],board[a] #board[board.index(0)], board[board.index(0)+1] = board[board.index(0)+1], board[board.index(0)] print('---------',m) print_board(board) #print(board[0],' ',board[1],' ',board[2]) #print(board[3],' ',board[4],' ',board[5]) #print(board[6],' ',board[7],' ',board[8]) return #------------------------------------------
# 633xxxxx21 548 (2020-09-18 20:44) def print_moves(board, moves): # bonus function: optional num = int(len(board)**0.5) zero = board.index(0) for i in range(0,len(board),3): x = [str(j) for j in board[i:i+3]] print(" ".join(x)) for e in moves: a =[] if e == "U": a += board[:zero-num]+[0]+board[zero-num+1:zero]+[board[zero-num]]+board[zero+1:] print("--------- "+e) for i in range(0,len(a),3): x = [str(j) for j in a[i:i+3]] print(" ".join(x)) board = [] for e in a: board.append(e) zero = board.index(0) elif e == "L": a += board[:zero-1]+[0]+[board[zero-1]]+board[zero+1:] print("--------- "+e) for i in range(0,len(a),3): x = [str(j) for j in a[i:i+3]] print(" ".join(x)) board = [] for e in a: board.append(e) zero = board.index(0) elif e == "R": a += board[:zero]+[board[zero+1]]+[0]+board[zero+2:] print("--------- "+e) for i in range(0,len(a),3): x = [str(j) for j in a[i:i+3]] print(" ".join(x)) board = [] for e in a: board.append(e) zero = board.index(0) elif e == "D": a += board[:zero]+[board[zero+num]]+board[zero+1:zero+num]+[0]+board[zero+num+1:] print("--------- "+e) for i in range(0,len(a),3): x = [str(j) for j in a[i:i+3]] print(" ".join(x)) board = [] for e in a: board.append(e) zero = board.index(0) return #------------------------------------------
# 633xxxxx21 549 (2020-09-20 20:09) def print_moves(board, moves): boards=[str(i) for i in board] x=boards[:] for i in range(0,7,3): print(" "+" ".join(boards[i:i+3])) print("--------- "+moves[0]) z=1 for i in moves: a=boards.index("0") if i=="U": boards[a],boards[a-3]=boards[a-3],boards[a] elif i=="R": boards[a],boards[a+1]=boards[a+1],boards[a] elif i=="L": boards[a],boards[a-1]=boards[a-1],boards[a] elif i=="D": boards[a],boards[a+3]=boards[a+3],boards[a] for k in range(0,7,3): print(" "+" ".join(boards[k:k+3])) if z!=len(moves) : print("--------- "+moves[z]) z+=1 return '' #------------------------------------------
# 633xxxxx21 550 (2020-09-20 18:31) def print_moves(board, moves): # bonus function: optional print() print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) for e in moves : if e == 'U': n = board.index(0) board[n],board[n-3] = board[n-3],board[n] print('----------',e) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) if e == 'D': n = board.index(0) board[n],board[n+3] = board[n+3],board[n] print('----------',e) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) if e == 'L': n = board.index(0) board[n],board[n-1] = board[n-1],board[n] print('----------',e) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) if e == 'R': n = board.index(0) board[n],board[n+1] = board[n+1],board[n] print('----------',e) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 551 (2020-09-20 23:08) def print_moves(board, moves): print() print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) for e in moves: if e == 'D': a = board.index(0) board[a],board[a+3] = board[a+3],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'L': a = board.index(0) board[a],board[a-1] = board[a-1],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'U': a = board.index(0) board[a],board[a-3] = board[a-3],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) elif e == 'R': a = board.index(0) board[a],board[a+1] = board[a+1],board[a] print('---------', e) print('',board[0],'', board[1],'', board[2]) print('',board[3],'', board[4],'', board[5]) print('',board[6],'',board[7],'', board[8]) return #------------------------------------------
# 633xxxxx21 552 (2020-09-19 22:25) def print_moves(board, moves): # bonus function: optional print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) for e in moves: if e == "U": print("---------","U") if board[3] == 0: board[3],board[0] = board[0],board[3] elif board[4] == 0: board[4],board[1] = board[1],board[4] elif board[5] == 0: board[5],board[2] = board[2],board[5] elif board[6] == 0: board[6],board[3] = board[3],board[6] elif board[7] == 0: board[7],board[4] = board[4],board[7] elif board[8] == 0: board[8],board[5] = board[5],board[8] elif e == "D": print("---------","D") if board[0] == 0: board[0],board[3] = board[3],board[0] elif board[1] == 0: board[1],board[4] = board[4],board[1] elif board[2] == 0: board[2],board[5] = board[5],board[2] elif board[3] == 0: board[3],board[6] = board[6],board[3] elif board[4] == 0: board[4],board[7] = board[7],board[4] elif board[5] == 0: board[5],board[8] = board[8],board[5] elif e == "L": print("---------","L") if board[1] == 0: board[1],board[0] = board[0],board[1] elif board[2] == 0: board[2],board[1] = board[1],board[2] elif board[4] == 0: board[4],board[3] = board[3],board[4] elif board[5] == 0: board[5],board[4] = board[4],board[5] elif board[7] == 0: board[7],board[6] = board[6],board[7] elif board[8] == 0: board[8],board[7] = board[7],board[8] elif e == "R": print("---------","R") if board[0] == 0: board[0],board[1] = board[1],board[0] elif board[1] == 0: board[1],board[2] = board[2],board[1] elif board[3] == 0: board[3],board[4] = board[4],board[3] elif board[4] == 0: board[4],board[5] = board[5],board[4] elif board[6] == 0: board[6],board[7] = board[7],board[6] elif board[7] == 0: board[7],board[8] = board[8],board[7] print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) return #------------------------------------------
# 633xxxxx21 553 (2020-09-20 22:42) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 554 (2020-09-20 22:09) def print_moves(board, moves): # bonus function: optional x=int(len(board)**0.5) for y in range(x): print(" ".join(str(z) for z in board[x*y:x*(y+1):])) for e in moves : print('---------',e) k=board.index(0) if e == 'U': board[k],board[k-3]=board[k-3],board[k] elif e == 'D': board[k],board[k+3]=board[k+3],board[k] elif e == 'L': board[k],board[k-1]=board[k-1],board[k] elif e == 'R': board[k],board[k+1]=board[k+1],board[k] for y in range(x): print(" ".join(str(z) for z in board[x*y:x*(y+1):])) return #------------------------------------------
# 633xxxxx21 555 (2020-09-20 23:53) def print_moves(board, moves): # bonus function: optional z = board.index(0) n = (len(board)) ** (1 / 2) n = int(n) for i in range(n): x = board[n * i:n * (i + 1)] for e in range(len(x)): x[e] = str(x[e]) print(' '.join(x)) for j in moves: print('--------------', j) if j == 'U': board[z], board[z - n] = board[z - n], board[z] elif j == 'D': board[z], board[z + n] = board[z + n], board[z] elif j == 'L': board[z], board[z - 1] = board[z - 1], board[z] elif j == 'R': board[z], board[z + 1] = board[z + 1], board[z] z = board.index(0) for i in range(n): x = board[n * i:n * (i + 1)] for e in range(len(x)): x[e] = str(x[e]) print(' '.join(x)) return # ------------------------------------------
# 633xxxxx21 556 (2020-09-18 23:46) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 557 (2020-09-20 10:21) def print_moves(board, moves): return #------------------------------------------
# 633xxxxx21 558 (2020-09-20 01:44) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 559 (2020-09-20 23:49) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 560 (2020-09-20 01:11) def print_moves(board, moves): # bonus function: optional k="" N=int((len(board))**0.5) a = list(board) for e in range(0,N**2): k+= str(a[e]) + " "*(3-len(str(a[e]))) if (e+1)%N == 0 : print(k) k="" for i in range(len(moves)) : location=a.index(0) if moves[i]=="U": a[location],a[location-N]=a[location-N],a[location] elif moves[i]=="D": a[location],a[location+N]=a[location+N],a[location] elif moves[i]=="L": a[location],a[location-1]=a[location-1],a[location] elif moves[i]=="R": a[location],a[location+1]=a[location+1],a[location] print("----------"+moves[i]) for e in range(0,N**2): k+= str(a[e]) + " "*(3-len(str(a[e]))) if (e+1)%N == 0 : print(k) k="" return #-------------successors-----------------------------
# 633xxxxx21 561 (2020-09-20 23:54) def print_moves(board, moves): # bonus function: optional c=int(len(board)**0.5) f=[] g=[] for i in range(c): w=c*(i+1) d=c*i f.append(w) g.append(d) q=[] for i in range(c): s=board[g[i]:f[i]] q.append(s) for i in range(c): x1='' x1=q[i] txt='' for i in range(c): txt+=str(x1[i]) txt+=' ' print(txt) for i in range(len(moves)): print('---------',moves[i]) if moves[i]=='R': a=board.index(0) board[a],board[a+1]=board[a+1],board[a] if moves[i]=='L': a=board.index(0) board[a],board[a-1]=board[a-1],board[a] if moves[i]=='U': a=board.index(0) board[a],board[a-c]=board[a-c],board[a] if moves[i]=='D': a=board.index(0) board[a],board[a+c]=board[a+c],board[a] c=int(len(board)**0.5) f=[] g=[] for i in range(c): w=c*(i+1) d=c*i f.append(w) g.append(d) q=[] for i in range(c): s=board[g[i]:f[i]] q.append(s) for i in range(c): x1='' x1=q[i] txt='' for i in range(c): txt+=str(x1[i]) txt+=' ' print(txt) return #------------------------------------------
# 633xxxxx21 562 (2020-09-19 20:54) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 563 (2020-09-19 18:42) def print_moves(board, moves): # bonus function: optional n = len(board) N = int(n**0.5) f = list(board) z = board.index(0) x = list(board) for e in moves: if e == 'U': z = x.index(0) x[z],x[z-N] = x[z-N],x[z] f += ['U'] + x elif e == 'D': z = x.index(0) x[z],x[z+N] = x[z+N],x[z] f += ['D'] + x elif e == 'R': z = x.index(0) x[z],x[z+1] = x[z+1],x[z] f += ['R'] + x elif e == 'L': z = x.index(0) x[z],x[z-1] = x[z-1],x[z] f += ['L'] + x d = "" i = 1 while i <= len(f): if i%(n+1) != 0: for t in range(-1,N-1): d += ' ' + str(f[i+t]) + ' ' print(d) d = '' i += N else: print('--------- ' + f[i-1]) i += 1 return #------------------------------------------
# 633xxxxx21 564 (2020-09-19 18:45) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 565 (2020-09-20 13:17) def print_moves(board, moves): # bonus function: optional N = 2 while N**2 != len(board): N +=1 for c in range(len(moves)+1): zero = board.index(0) if c !=0: if moves[c-1] =='U': print('--------- U') board[zero],board[zero-N]=board[zero-N],board[zero] elif moves[c-1] =='D': board[zero],board[zero+N]=board[zero+N],board[zero] print('--------- D') elif moves[c-1] =='L': board[zero],board[zero-1]=board[zero-1],board[zero] print('--------- L') elif moves[c-1] =='R': board[zero],board[zero+1]=board[zero+1],board[zero] print('--------- R') for i in range(N): b_str = '' for j in range(N): b_str += ' '+str(board[j+(N*i)]) if j!=N-1: b_str += ' ' print(b_str) return #------------------------------------------
# 633xxxxx21 566 (2020-09-20 22:26) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 567 (2020-09-20 18:40) def print_moves(board, moves): for i in range(0,9,3) : b = i+2 while i < b : print(board[i],end=' ') i+=1 print(board[i]) for i in moves : print(9*'-'+i) a = gen_successors(board + ['UDR']) N = 1 for e in a: if type(e) is str: break N += 1 for j in range(0,len(a),N): c = a[j:j+N] if c[-1][-1] == i : d = c for l in range(0,9,3) : y = l+2 while l < y : g = d[:-1] print(g[l],end=' ') l+=1 print(g[l]) board = d return # bonus function: option #------------------------------------------ def gen_successors(node): successors = [] a = [] b = [] c = [] d = [] for i in node : a.append(i) for i in node : b.append(i) for i in node : c.append(i) for i in node : d.append(i) if node.index(0) == 0 : M = ['R','D'] for i in M: if i == 'R': a[0],a[1]=a[1],a[0] successors+=(a[0:9] + [node[-1]+i]) elif i == 'D': b[0],b[3]=b[3],b[0] successors+=(b[0:9] + [node[-1]+i]) elif node.index(0) == 1 : M = ['R','D','L'] for i in M: if i =='R': a[1],a[2]=a[2],a[1] successors+=(a[0:9] + [node[-1]+i]) elif i == 'D': b[1],b[4]=b[4],b[1] successors+=(b[0:9] + [node[-1]+i]) elif i == 'L': d[0],d[1]=d[1],d[0] successors+=(d[0:9] + [node[-1]+i]) elif node.index(0) == 2 : M = ['L','D'] for i in M: if i == 'L': d[1],d[2]=d[2],d[1] successors+=(d[0:9] + [node[-1]+i]) elif i == 'D': b[2],b[5]=b[5],b[2] successors+=(b[0:9] + [node[-1]+i]) elif node.index(0) == 3 : M = ['R','D','U'] for i in M: if i == 'R': b[3],b[4]=b[4],b[3] successors+=(b[0:9] + [node[-1]+i]) elif i == 'D': d[3],d[6]=d[6],d[3] successors+=(d[0:9] + [node[-1]+i]) elif i == 'U': a[0],a[3]=a[3],a[0] successors+=(a[0:9] + [node[-1]+i]) elif node.index(0) == 4 : M = ['R','D','L','U'] for i in M: if i == 'R': b[4],b[5]=b[5],b[4] successors+=(b[0:9] + [node[-1]+i]) elif i == 'D': d[4],d[7]=d[7],d[4] successors+=(d[0:9] + [node[-1]+i]) elif i == 'L': a[3],a[4]=a[4],a[3] successors+=(a[0:9] + [node[-1]+i]) elif i == 'U': c[1],c[4]=c[4],c[1] successors+=(c[0:9] + [node[-1]+i]) elif node.index(0) == 5 : M = ['U','D','L'] for i in M: if i == 'U': c[2],c[5]=c[5],c[2] successors+=(c[0:9] + [node[-1]+i]) elif i == 'D': a[5],a[8]=a[8],a[5] successors+=(a[0:9] + [node[-1]+i]) elif i == 'L': b[4],b[5]=b[5],b[4] successors+=(b[0:9] + [node[-1]+i]) elif node.index(0) == 6 : M = ['R','U'] for i in M: if i == 'R': b[6],b[7]=b[7],b[6] successors+=(b[0:9] + [node[-1]+i]) elif i == 'U': c[3],c[6]=c[6],c[3] successors+=(c[0:9] + [node[-1]+i]) elif node.index(0) == 7 : M = ['R','U','L'] for i in M: if i == 'R': a[7],a[8]=a[8],a[7] successors+=(a[0:9] + [node[-1]+i]) elif i == 'U': b[4],b[7]=b[7],b[4] successors+=(b[0:9] + [node[-1]+i]) elif i == 'L': c[6],c[7]=c[7],c[6] successors+=(c[0:9] + [node[-1]+i]) elif node.index(0) == 8 : M = ['L','U'] for i in M: if i == 'L': a[7],a[8]=a[8],a[7] successors+=(a[0:9] + [node[-1]+i]) elif i == 'U': c[5],c[8]=c[8],c[5] successors+=(c[0:9] + [node[-1]+i]) return successors #------------------------------------------
# 633xxxxx21 568 (2020-09-20 15:24) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 569 (2020-09-20 23:43) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 570 (2020-09-18 20:46) def print_moves(board, moves): # bonus function: optional for i in range(0,len(board),3): print(str(board[i])+" "+str(board[i+1])+" "+str(board[i+2])) for i in range(len(moves)): location=board.index(0,0,len(board)) if moves[i]=="U": board[location],board[location-3]=board[location-3],board[location] elif moves[i]=="D": board[location],board[location+3]=board[location+3],board[location] elif moves[i]=="L": board[location],board[location-1]=board[location-1],board[location] elif moves[i]=="R": board[location],board[location+1]=board[location+1],board[location] print("------"+moves[i]) for j in range(0,len(board),3): print(str(board[j])+" "+str(board[j+1])+" "+str(board[j+2])) return #------------------------------------------
# 633xxxxx21 571 (2020-09-20 18:42) def print_moves(board, moves): # bonus function: optional N = int(len(board)**0.5) for i in range(0,N**2,N): k = i + N - 1 while i < k: print(board[i],end = " ") i += 1 print(board[i]) return #------------------------------------------
# 633xxxxx21 572 (2020-09-19 00:10) def print_moves(board, moves): N = int(len(board)**0.5) for i in range(0,N**2,N) : k=i+N-1 while i < k : print(' '+str(board[i]),end=' ') i+=1 print(' '+str(board[i])) for c in moves : print(N**2*'-',c) i=board.index(0) if c == 'D' : board[i],board[i+N]=board[i+N],board[i] elif c == 'R' : board[i],board[i+1]=board[i+1],board[i] elif c == 'U' : board[i],board[i-N]=board[i-N],board[i] elif c == 'L' : board[i],board[i-1]=board[i-1],board[i] for i in range(0,N**2,N) : k=i+N-1 while i < k : print(' '+str(board[i]),end=' ') i+=1 print(' '+str(board[i])) return #------------------------------------------
# 633xxxxx21 573 (2020-09-20 21:42) def print_moves(board, moves): # bonus function: optional pass #return #------------------------------------------
# 633xxxxx21 574 (2020-09-20 22:43) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 575 (2020-09-20 14:51) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 576 (2020-09-20 21:41) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 577 (2020-09-20 17:59) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 578 (2020-09-20 19:54) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 579 (2020-09-19 13:07) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 580 (2020-09-20 20:21) def print_moves(board, moves): # bonus function: optional a=board.index(0) N = int(len(board)**0.5) for e in range(len(moves)): for i in range(0,N**2,N): x = i+N-1 while i<x: print('',board[i],end=' ') i+=1 print('',board[i]) print(N**2*'-'+moves[e]) if moves[e]=="U": board.remove(0) board.insert(a-3,0) board.insert(a+1,board[a-2]) board.pop(a-2) elif moves[e]=="D": board.remove(0) board.insert(a+2,0) board.insert(a,board[a+3]) board.pop(a+4) elif moves[e]=="L": board.remove(0) board.insert(a-1,0) elif moves[e]=="R": board.remove(0) board.insert(a+1,0) a=board.index(0) for i in range(0,N**2,N): x = i+N-1 while i<x: print('',board[i],end=' ') i+=1 print('',board[i]) return #------------------------------------------
# 633xxxxx21 581 (2020-09-20 12:31) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 582 (2020-09-20 21:53) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 583 (2020-09-20 22:03) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 584 (2020-09-20 01:14) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 585 (2020-09-20 23:52) def print_moves(board, moves): # bonus function: optional new = list(board) N = int(len(board)**0.5) for i in range(0,len(board),N): p = "" for j in range(i,i+N): p += str(board[j])+" " print(p) for e in moves: print("--------- "+e) si=new.index(0,0,len(new)) if e=="R": new[si],new[si+1] = new[si+1],new[si] elif e=="U": new[si],new[si-3] = new[si-3],new[si] elif e=="D": new[si],new[si+3] = new[si+3],new[si] elif e=="L": new[si],new[si-1] = new[si-1],new[si] for i in range(0,len(board),N): p = "" for j in range(i,i+N): p += str(new[j])+" " print(p) return #------------------------------------------
# 633xxxxx21 586 (2020-09-20 21:33) def print_moves(board, moves): a=board[:] print(a[0],a[1],a[2]) print(a[3],a[4],a[5]) print(a[6],a[7],a[8]) for i in range(len(moves)): g=a.index(0) if g==0: if moves[i] == "R": a[0],a[1]=a[1],a[0] if moves[i] == "D": a[0],a[3]=a[3],a[0] if g==2: if moves[i] == "L": a[2],a[1]=a[1],a[2] if moves[i] == "D": a[2],a[5]=a[5],a[2] if g==6: if moves[i] == "U": a[6],a[3]=a[3],a[6] if moves[i] == "R": a[6],a[7]=a[7],a[6] if g==8: if moves[i] == "U": a[8],a[5]=a[5],a[8] if moves[i]=="L": a[8],a[7]=a[7],a[8] if g==1: if moves[i] == "R": a[1],a[2]=a[2],a[1] if moves[i] == "L": a[1],a[0]=a[0],a[1] if moves[i] == "D": a[1],a[4]=a[4],a[1] if g==3: if moves[i] == "R": a[3],a[4]=a[4],a[3] if moves[i] == "U": a[3],a[0]=a[0],a[3] if moves[i] == "D": a[3],a[6]=a[6],a[3] if g==5: if moves[i] == "U": a[5],a[2]=a[2],a[5] if moves[i] == "D": a[5],a[8]=a[8],a[5] if moves[i] == "L": a[5],a[4]=a[4],a[5] if g==7: if moves[i] == "L": a[7],a[6]=a[6],a[7] if moves[i] == "R": a[7],a[8]=a[8],a[7] if moves[i] == "U": a[7],a[4]=a[4],a[7] if g==4: if moves[i] == "R": a[4],a[5]=a[5],a[4] if moves[i] == "L": a[4],a[3]=a[3],a[4] if moves[i] == "U": a[4],a[1]=a[1],a[4] if moves[i] == "D": a[4],a[7]=a[7],a[4] print("---------"+moves[i]) print(a[0],a[1],a[2]) print(a[3],a[4],a[5]) print(a[6],a[7],a[8]) #------------------------------------------
# 633xxxxx21 587 (2020-09-20 22:16) def print_moves(board, moves): board = [1,2,3,4,5,6,7,8,0] moves = bfs(board) return #------------------------------------------ def bfs(board): start_node = board + [''] fringe = [start_node] while True: if len(fringe) == 0: break front = fringe[0] fringe = fringe[1:] if is_goal(front): return front[-1] insert_all(front,fringe) return '' def is_goal(node): return node[:-1] == \ list(range(1,len(node)-1))+[0] def insert_all(node, fringe): n = len(node) children = gen_successors(node) for i in range(0,len(children),n): fringe.append(children[i:i+n]) def gen_successors(node): successors = [] node = board + ["UDR"] N = int(len(board)**0.5) M = int(len(board)) x = node.index(0) a = [0]*(N-2) for i in range(len(a)) : a[i] = i+1 b = [0]*(N-2) for i in range(len(b)) : b[i] = (i+1)*N c = [0]*(N-2) for i in range(len(c)) : c[i] = ((2+i)*N)-1 d = [0]*(N-2) for i in range(len(d)) : d[i] = (N**2)-N+1+i e = [0]*(N-2) k = [0]*(N-2) for i in range(N-2) : e[i] = N+i+1 for i in range(N-2) : k[i] = N+i+1 for i in range(N-3) : for i in range(len(k)) : k[i] += N e += k if x == 0 : node[0],node[1] = node[1],node[0] successors += node[:-1:] successors.append(node[-1]+"R") node[0],node[1] = node[1],node[0] node[0],node[N] = node[N],node[0] successors += node[:-1:] successors.append(node[-1]+"D") if x in a : node[x],node[x+N] = node[x+N],node[x] successors += node[:-1:] successors.append(node[-1]+"D") node[x],node[x+N] = node[x+N],node[x] node[x],node[x-1] = node[x-1],node[x] successors += node[:-1:] successors.append(node[-1]+"L") node[x],node[x-1] = node[x-1],node[x] node[x],node[x+1] = node[x+1],node[x] successors += node[:-1:] successors.append(node[-1]+"R") if x == N-1 : node[N-1],node[N-2] = node[N-2],node[N-1] successors += node[:-1:] successors.append(node[-1]+"L") node[N-1],node[N-2] = node[N-2],node[N-1] node[N-1],node[2*N-1] = node[2*N-1],node[N-1] successors += node[:-1:] successors.append(node[-1]+"D") if x in b : node[x],node[x-N] = node[x-N],node[x] successors += node[:-1:] successors.append(node[-1]+"U") node[x],node[x-N] = node[x-N],node[x] node[x],node[x+N] = node[x+N],node[x] successors += node[:-1:] successors.append(node[-1]+"D") node[x],node[x+N] = node[x+N],node[x] node[x],node[x+1] = node[x+1],node[x] successors += node[:-1:] successors.append(node[-1]+"R") if x in e : node[x],node[x-N] = node[x-N],node[x] successors += node[:-1:] successors.append(node[-1]+"U") node[x],node[x-N] = node[x-N],node[x] node[x],node[x+N] = node[x+N],node[x] successors += node[:-1:] successors.append(node[-1]+"D") node[x],node[x+N] = node[x+N],node[x] node[x],node[x-1] = node[x-1],node[x] successors += node[:-1:] successors.append(node[-1]+"L") node[x],node[x-1] = node[x-1],node[x] node[x],node[x+1] = node[x+1],node[x] successors += node[:-1:] successors.append(node[-1]+"R") if x in c : node[x],node[x-N] = node[x-N],node[x] successors += node[:-1:] successors.append(node[-1]+"U") node[x],node[x-N] = node[x-N],node[x] node[x],node[x+N] = node[x+N],node[x] successors += node[:-1:] successors.append(node[-1]+"D") node[x],node[x+N] = node[x+N],node[x] node[x],node[x-1] = node[x-1],node[x] successors += node[:-1:] successors.append(node[-1]+"L") if x == M-N : node[M-N],node[N*(N-2)] = node[N*(N-2)],node[M-N] successors += node[:-1:] successors.append(node[-1]+"U") node[M-N],node[N*(N-2)] = node[N*(N-2)],node[M-N] node[M-N],node[M-N+1] = node[M-N+1],node[M-N] successors += node[:-1:] successors.append(node[-1]+"R") if x in d : node[x],node[x-N] = node[x-N],node[x] successors += node[:-1:] successors.append(node[-1]+"U") node[x],node[x-N] = node[x-N],node[x] node[x],node[x-1] = node[x-1],node[x] successors += node[:-1:] successors.append(node[-1]+"L") node[x],node[x-1] = node[x-1],node[x] node[x],node[x+1] = node[x+1],node[x] successors += node[:-1:] successors.append(node[-1]+"R") if x == M-1 : node[M-1],node[M-N-1] = node[M-N-1],node[M-1] successors += node[:-1:] successors.append(node[-1]+"U") node[M-1],node[M-N-1] = node[M-N-1],node[M-1] node[M-1],node[M-2] = node[M-2],node[M-1] successors += node[:-1:] successors.append(node[-1]+"L") return successors #------------------------------------------
# 633xxxxx21 588 (2020-09-20 22:53) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 589 (2020-09-20 20:00) def print_moves(board, moves):# bonus function: optional return #------------------------------------------
# 633xxxxx21 590 (2020-09-20 20:45) def print_moves(board, moves): board = [1,2,3,4,5,6,7,8,0] moves = bfs(board) return #------------------------------------------ def bfs(board): start_node = board + [''] fringe = [start_node] while True: if len(fringe) == 0: break front = fringe[0] fringe = fringe[1:] if is_goal(front): return front[-1] insert_all(front,fringe) return '' def is_goal(node): return node[:-1] == \ list(range(1,len(node)-1))+[0] def insert_all(node, fringe): n = len(node) children = gen_successors(node) for i in range(0,len(children),n): fringe.append(children[i:i+n]) def gen_successors(node): successors = [] node = board + ["UDR"] N = int(len(board)**0.5) M = int(len(board)) x = node.index(0) a,b,c = [0]*(N-2),[0]*(N-2),[0]*(N-2) d,e,q = [0]*(N-2),[0]*(N-2),[0]*(N-2) for i in range(len(a)) : a[i] = i+1 for i in range(len(b)) : b[i] = (i+1)*N for i in range(len(c)) : c[i] = ((2+i)*N)-1 for i in range(len(d)) : d[i] = (N**2)-N+1+i for i in range(N-2) : e[i] = N+i+1 for i in range(N-2) : q[i] = N+i+1 for i in range(N-3) : for i in range(len(q)) : q[i] += N e += q if x == 0 : node[0],node[1] = node[1],node[0] successors += node[:-1:] successors.append(node[-1]+"R") node[0],node[1] = node[1],node[0] node[0],node[N] = node[N],node[0] successors += node[:-1:] successors.append(node[-1]+"D") if x == N-1 : node[N-1],node[N-2] = node[N-2],node[N-1] successors += node[:-1:] successors.append(node[-1]+"L") node[N-1],node[N-2] = node[N-2],node[N-1] node[N-1],node[2*N-1] = node[2*N-1],node[N-1] successors += node[:-1:] successors.append(node[-1]+"D") if x == M-N : node[M-N],node[N*(N-2)] = node[N*(N-2)],node[M-N] successors += node[:-1:] successors.append(node[-1]+"U") node[M-N],node[N*(N-2)] = node[N*(N-2)],node[M-N] node[M-N],node[M-N+1] = node[M-N+1],node[M-N] successors += node[:-1:] successors.append(node[-1]+"R") if x == M-1 : node[M-1],node[M-N-1] = node[M-N-1],node[M-1] successors += node[:-1:] successors.append(node[-1]+"U") node[M-1],node[M-N-1] = node[M-N-1],node[M-1] node[M-1],node[M-2] = node[M-2],node[M-1] successors += node[:-1:] successors.append(node[-1]+"L") if x in a : node[x],node[x+N] = node[x+N],node[x] successors += node[:-1:] successors.append(node[-1]+"D") node[x],node[x+N] = node[x+N],node[x] node[x],node[x-1] = node[x-1],node[x] successors += node[:-1:] successors.append(node[-1]+"L") node[x],node[x-1] = node[x-1],node[x] node[x],node[x+1] = node[x+1],node[x] successors += node[:-1:] successors.append(node[-1]+"R") if x in b : node[x],node[x-N] = node[x-N],node[x] successors += node[:-1:] successors.append(node[-1]+"U") node[x],node[x-N] = node[x-N],node[x] node[x],node[x+N] = node[x+N],node[x] successors += node[:-1:] successors.append(node[-1]+"D") node[x],node[x+N] = node[x+N],node[x] node[x],node[x+1] = node[x+1],node[x] successors += node[:-1:] successors.append(node[-1]+"R") if x in c : node[x],node[x-N] = node[x-N],node[x] successors += node[:-1:] successors.append(node[-1]+"U") node[x],node[x-N] = node[x-N],node[x] node[x],node[x+N] = node[x+N],node[x] successors += node[:-1:] successors.append(node[-1]+"D") node[x],node[x+N] = node[x+N],node[x] node[x],node[x-1] = node[x-1],node[x] successors += node[:-1:] successors.append(node[-1]+"L") if x in d : node[x],node[x-N] = node[x-N],node[x] successors += node[:-1:] successors.append(node[-1]+"U") node[x],node[x-N] = node[x-N],node[x] node[x],node[x-1] = node[x-1],node[x] successors += node[:-1:] successors.append(node[-1]+"L") node[x],node[x-1] = node[x-1],node[x] node[x],node[x+1] = node[x+1],node[x] successors += node[:-1:] successors.append(node[-1]+"R") if x in e : node[x],node[x-N] = node[x-N],node[x] successors += node[:-1:] successors.append(node[-1]+"U") node[x],node[x-N] = node[x-N],node[x] node[x],node[x+N] = node[x+N],node[x] successors += node[:-1:] successors.append(node[-1]+"D") node[x],node[x+N] = node[x+N],node[x] node[x],node[x-1] = node[x-1],node[x] successors += node[:-1:] successors.append(node[-1]+"L") node[x],node[x-1] = node[x-1],node[x] node[x],node[x+1] = node[x+1],node[x] successors += node[:-1:] successors.append(node[-1]+"R") return successors #------------------------------------------
# 633xxxxx21 591 (2020-09-20 15:10) def print_moves(board, moves): board = [1,2,3,4,5,6,7,8,0] moves = bfs(board) return #------------------------------------------ def bfs(board): start_node = board + [''] fringe = [start_node] while True: if len(fringe) == 0: break front = fringe[0] fringe = fringe[1:] if is_goal(front): return front[-1] insert_all(front,fringe) return '' def is_goal(node): return node[:-1] == \ list(range(1,len(node)-1))+[0] def insert_all(node, fringe): n = len(node) children = gen_successors(node) for i in range(0,len(children),n): fringe.append(children[i:i+n]) def gen_successors(node): successors = [] node = board + ["RUD"] N = int(len(board)**(1/2)) M = int(len(board)) x = node.index(0) A = [0]*(N-2) for i in range(len(A)) : A[i] = i+1 B = [0]*(N-2) for i in range(len(B)) : B[i] = (i+1)*N C = [0]*(N-2) for i in range(len(C)) : C[i] = ((2+i)*N)-1 D = [0]*(N-2) for i in range(len(D)) : D[i] = (N**2)-N+1+i E = [0]*(N-2) F = [0]*(N-2) for i in range(N-2) : E[i] = N+i+1 for i in range(N-2) : F[i] = N+i+1 for i in range(N-3) : for i in range(len(F)) : F[i] += N E += F if x == 0 : node[0],node[1] = node[1],node[0] successors += node[:-1:] successors.append(node[-1]+"R") node[0],node[1] = node[1],node[0] node[0],node[N] = node[N],node[0] successors += node[:-1:] successors.append(node[-1]+"D") elif x == N-1 : node[N-1],node[N-2] = node[N-2],node[N-1] successors += node[:-1:] successors.append(node[-1]+"L") node[N-1],node[N-2] = node[N-2],node[N-1] node[N-1],node[2*N-1] = node[2*N-1],node[N-1] successors += node[:-1:] successors.append(node[-1]+"D") elif x == M-N : node[M-N],node[N*(N-2)] = node[N*(N-2)],node[M-N] successors += node[:-1:] successors.append(node[-1]+"U") node[M-N],node[N*(N-2)] = node[N*(N-2)],node[M-N] node[M-N],node[M-N+1] = node[M-N+1],node[M-N] successors += node[:-1:] successors.append(node[-1]+"R") elif x == M-1 : node[M-1],node[M-N-1] = node[M-N-1],node[M-1] successors += node[:-1:] successors.append(node[-1]+"U") node[M-1],node[M-N-1] = node[M-N-1],node[M-1] node[M-1],node[M-2] = node[M-2],node[M-1] successors += node[:-1:] successors.append(node[-1]+"L") elif x in A : node[x],node[x+N] = node[x+N],node[x] successors += node[:-1:] successors.append(node[-1]+"D") node[x],node[x+N] = node[x+N],node[x] node[x],node[x-1] = node[x-1],node[x] successors += node[:-1:] successors.append(node[-1]+"L") node[x],node[x-1] = node[x-1],node[x] node[x],node[x+1] = node[x+1],node[x] successors += node[:-1:] successors.append(node[-1]+"R") elif x in B : node[x],node[x-N] = node[x-N],node[x] successors += node[:-1:] successors.append(node[-1]+"U") node[x],node[x-N] = node[x-N],node[x] node[x],node[x+N] = node[x+N],node[x] successors += node[:-1:] successors.append(node[-1]+"D") node[x],node[x+N] = node[x+N],node[x] node[x],node[x+1] = node[x+1],node[x] successors += node[:-1:] successors.append(node[-1]+"R") elif x in C : node[x],node[x-N] = node[x-N],node[x] successors += node[:-1:] successors.append(node[-1]+"U") node[x],node[x-N] = node[x-N],node[x] node[x],node[x+N] = node[x+N],node[x] successors += node[:-1:] successors.append(node[-1]+"D") node[x],node[x+N] = node[x+N],node[x] node[x],node[x-1] = node[x-1],node[x] successors += node[:-1:] successors.append(node[-1]+"L") elif x in D : node[x],node[x-N] = node[x-N],node[x] successors += node[:-1:] successors.append(node[-1]+"U") node[x],node[x-N] = node[x-N],node[x] node[x],node[x-1] = node[x-1],node[x] successors += node[:-1:] successors.append(node[-1]+"L") node[x],node[x-1] = node[x-1],node[x] node[x],node[x+1] = node[x+1],node[x] successors += node[:-1:] successors.append(node[-1]+"R") elif x in E : node[x],node[x-N] = node[x-N],node[x] successors += node[:-1:] successors.append(node[-1]+"U") node[x],node[x-N] = node[x-N],node[x] node[x],node[x+N] = node[x+N],node[x] successors += node[:-1:] successors.append(node[-1]+"D") node[x],node[x+N] = node[x+N],node[x] node[x],node[x-1] = node[x-1],node[x] successors += node[:-1:] successors.append(node[-1]+"L") node[x],node[x-1] = node[x-1],node[x] node[x],node[x+1] = node[x+1],node[x] successors += node[:-1:] successors.append(node[-1]+"R") return successors #------------------------------------------
# 633xxxxx21 592 (2020-09-20 22:41) def print_moves(board, moves):# bonus function: optional return #------------------------------------------
# 633xxxxx21 593 (2020-09-20 21:40) def print_moves(board, moves): # bonus function: optional board=[str(e) for e in board] n=int(len(board)**0.5) for i in range (0,len(board),n): print(' '.join(board[i:i+n])) for e in moves: print("---------",e) if '0' in board: idx = board.index('0') if e =='U': board[idx],board[idx-n]=board[idx-n],board[idx] elif e =='D': board[idx],board[idx+n]=board[idx+n],board[idx] elif e =='R': board[idx],board[idx+1]=board[idx+1],board[idx] elif e =='L': board[idx],board[idx-1]=board[idx-1],board[idx] for i in range (0,len(board),n): print(' '.join(board[i:i+n])) return #------------------------------------------
# 633xxxxx21 594 (2020-09-20 21:54) def print_moves(board, moves): # bonus function: optional print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) for i in range(len(moves)): print("-"*9+moves[i]) pos = board.index(0) if moves[i] == "R": board[pos],board[pos+1]=board[pos+1],board[pos] if moves[i] == "L": board[pos],board[pos-1]=board[pos-1],board[pos] if moves[i] == "D": board[pos],board[pos+3]=board[pos+3],board[pos] if moves[i] == "U": board[pos],board[pos-3]=board[pos-3],board[pos] print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) return #------------------------------------------
# 633xxxxx21 595 (2020-09-20 23:04) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)): print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print('-----------', moves[i]) b = board.index(0) if moves[i] == 'D' : board.remove(0) board.insert(b+2,0) board.insert(b,board[b+3]) board.pop(b+4) elif moves[i] == 'L' : board.remove(0) board.insert(b-1,0) elif moves[i] == 'R' : board.remove(0) board.insert(b+1,0) elif moves[i] == 'U' : board.remove(0) board.insert(b-3,0) board.insert(b+1,board[b-2]) board.pop(b-2) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 596 (2020-09-20 23:51) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 597 (2020-09-20 21:29) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 598 (2020-09-20 17:31) def print_moves(board, moves): # bonus function: optional #start_board print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) num = len(moves) for i in range(num): mv = moves[i] print("-----",moves[i]) if 0 == board[0]: if mv == "D": board[0],board[3] = board[3],board[0] elif mv == "R": board[0],board[1] = board[1],board[0] elif 0 == board[1]: if mv == "L": board[0],board[1] = board[1],board[0] elif mv == "R": board[1],board[2] = board[2],board[1] elif mv == "D": board[1],board[4] = board[4],board[1] elif 0 == board[2]: if mv == "D": board[2],board[5] = board[5],board[2] elif mv == "L": board[1],board[2] = board[2],board[1] elif 0 == board[3]: if mv == "U": board[0],board[3] = board[3],board[0] elif mv == "R": board[3],board[4] = board[4],board[3] elif mv == "D": board[3],board[6] = board[6],board[3] elif 0 == board[4]: if mv == "U": board[1],board[4] = board[4],board[1] elif mv == "R": board[4],board[5] = board[5],board[4] elif mv == "D": board[4],board[7] = board[7],board[4] elif mv == "L": board[3],board[4] = board[4],board[3] elif 0 == board[5]: if mv == "U": board[2],board[5] = board[5],board[2] elif mv == "L": board[4],board[5] = board[5],board[4] elif mv == "D": board[5],board[8] = board[8],board[5] elif 0 == board[6]: if mv == "U": board[3],board[6] = board[6],board[3] elif mv == "R": board[6],board[7] = board[7],board[6] elif 0 == board[7]: if mv == "L": board[6],board[7] = board[7],board[6] elif mv == "R": board[7],board[8] = board[8],board[7] elif mv == "U": board[4],board[7] = board[7],board[4] elif 0 == board[8]: if mv == "U": board[5],board[8] = board[8],board[5] elif mv == "L": board[7],board[8] = board[8],board[7] print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) return #------------------------------------------
# 633xxxxx21 599 (2020-09-20 20:22) def print_moves(board, moves): for i in range(len(moves)): print(" ", board[0], " ", board[1], " ", board[2]) print(" ", board[3], " ", board[4], " ", board[5]) print(" ", board[6], " ", board[7], " ", board[8]) print("---------------", move[i]) B = board.index(0) if moves[i] == "U": board.remove(0) board.insert(B-3,0) board.insert(B+1,board[B-2]) board.pop(B-2) elif moves[i] == "R": board.remove(0) board.insert(B+1,0) elif moves[i] == "L": board.remove(0) board.insert(B-1,0) elif moves[i] == "D": board.remove(0) board.insert(B+2,0) board.insert(B,board[B+3]) board.pop(B+4) print(" ", board[0], " ", board[1], " ", board[2]) print(" ", board[3], " ", board[4], " ", board[5]) print(" ", board[6], " ", board[7], " ", board[8]) # bonus function: optional return #------------------------------------------
# 633xxxxx21 600 (2020-09-20 14:13) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 601 (2020-09-20 16:07) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 602 (2020-09-20 19:58) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 603 (2020-09-20 21:12) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 604 (2020-09-20 23:50) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)): print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print('-----------', moves[i]) b = board.index(0) if moves[i] == 'D' : board.remove(0) board.insert(b+2,0) board.insert(b,board[b+3]) board.pop(b+4) elif moves[i] == 'L' : board.remove(0) board.insert(b-1,0) elif moves[i] == 'R' : board.remove(0) board.insert(b+1,0) elif moves[i] == 'U' : board.remove(0) board.insert(b-3,0) board.insert(b+1,board[b-2]) board.pop(b-2) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 605 (2020-09-19 17:23) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 606 (2020-09-20 21:03) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 607 (2020-09-20 21:28) def print_moves(board, moves): # bonus function: optional N = int(len(board)**(1/2)) lse = [] y = 1 for i in board: lse.append(str(i)) while y <= N: x = lse[(y-1)*N:y*N] x = " ".join(x) y += 1 print(x) y = 1 for q in range(len(moves)): print("-------", moves[q]) A = board.index(0) if moves[q] == "D": #Go Down C = board.pop(A+N) board.insert(A,C) board.remove(0) board.insert(A+N,0) elif moves[q] == "R": #Go Right C = board.pop(A+1) board.insert(A,C) board.remove(0) board.insert(A+1,0) elif moves[q] == "L": #Go Left C = board.pop(A-1) board.insert(A,C) board.remove(0) board.insert(A-1,0) elif moves[q] == "U": #Go Up C = board.pop(A-N) board.insert(A,C) board.remove(0) board.insert(A-N,0) y = 1 lse = [] for i in board: lse.append(str(i)) while y <= N: x = lse[(y-1)*N:y*N] x = " ".join(x) y += 1 print(x) return #------------------------------------------
# 633xxxxx21 608 (2020-09-20 22:54) def print_moves(board, moves): def swap(board, p1, p2): board[p1], board[p2] = board[p2], board[p1] return board N = int(len(board)**0.5) for pos, num in enumerate(board): if num == 0: blank = pos for move in moves: if move == "U": swap(board, blank, blank + (-N)) blank += (-N) elif move == "D": swap(board, blank, blank + (N)) blank += (N) elif move == "L": swap(board, blank, blank + (-1)) blank += (-1) elif move == "R": swap(board, blank, blank + (1)) blank += (1) for i in range(N**2): print(board[i], " ", end = "") if (i+1) % N == 0: print("") print("---------", move) return None #------------------------------------------
# 633xxxxx21 609 (2020-09-20 23:53) def print_moves(board, moves): # bonus function: optional #start_board print("-----") print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) num = len(moves) for i in range(num): mv = moves[i] print("-----",moves[i]) if 0 == board[0]: if mv == "D": board[0],board[3] = board[3],board[0] elif mv == "R": board[0],board[1] = board[1],board[0] elif 0 == board[1]: if mv == "D": board[1],board[4] = board[4],board[1] elif mv == "L": board[0],board[1] = board[1],board[0] elif mv == "R": board[1],board[2] = board[2],board[1] elif 0 == board[2]: if mv == "D": board[2],board[5] = board[5],board[2] elif mv == "L": board[1],board[2] = board[2],board[1] elif 0 == board[3]: if mv == "U": board[0],board[3] = board[3],board[0] elif mv == "D": board[3],board[6] = board[6],board[3] elif mv == "R": board[3],board[4] = board[4],board[3] elif 0 == board[4]: if mv == "U": board[1],board[4] = board[4],board[1] elif mv == "D": board[4],board[7] = board[7],board[4] elif mv == "L": board[3],board[4] = board[4],board[3] elif mv == "R": board[4],board[5] = board[5],board[4] elif 0 == board[5]: if mv == "U": board[2],board[5] = board[5],board[2] elif mv == "D": board[5],board[8] = board[8],board[5] elif mv == "L": board[4],board[5] = board[5],board[4] elif 0 == board[6]: if mv == "U": board[3],board[6] = board[6],board[3] elif mv == "R": board[6],board[7] = board[7],board[6] elif 0 == board[7]: if mv == "U": board[4],board[7] = board[7],board[4] elif mv == "L": board[6],board[7] = board[7],board[6] elif mv == "R": board[7],board[8] = board[8],board[7] elif 0 == board[8]: if mv == "U": board[5],board[8] = board[8],board[5] elif mv == "L": board[7],board[8] = board[8],board[7] print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) return #------------------------------------------
# 633xxxxx21 610 (2020-09-20 23:56) def print_moves(board, moves):# bonus function: optional return #------------------------------------------
# 633xxxxx21 611 (2020-09-20 23:27) def print_moves(board, moves): # bonus function: optional #start_board print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) num = len(moves) for i in range(num): M = moves[i] print("-----",moves[i]) if 0 == board[0]: if M == "D": board[0],board[3] = board[3],board[0] elif M == "R": board[0],board[1] = board[1],board[0] elif 0 == board[1]: if M == "L": board[0],board[1] = board[1],board[0] elif M == "R": board[1],board[2] = board[2],board[1] elif M == "D": board[1],board[4] = board[4],board[1] elif 0 == board[2]: if M == "D": board[2],board[5] = board[5],board[2] elif M == "L": board[1],board[2] = board[2],board[1] elif 0 == board[3]: if M == "U": board[0],board[3] = board[3],board[0] elif M == "R": board[3],board[4] = board[4],board[3] elif M == "D": board[3],board[6] = board[6],board[3] elif 0 == board[4]: if M == "U": board[1],board[4] = board[4],board[1] elif M == "R": board[4],board[5] = board[5],board[4] elif M == "D": board[4],board[7] = board[7],board[4] elif M == "L": board[3],board[4] = board[4],board[3] elif 0 == board[5]: if M == "U": board[2],board[5] = board[5],board[2] elif M == "L": board[4],board[5] = board[5],board[4] elif M == "D": board[5],board[8] = board[8],board[5] elif 0 == board[6]: if M == "U": board[3],board[6] = board[6],board[3] elif M == "R": board[6],board[7] = board[7],board[6] elif 0 == board[7]: if M == "L": board[6],board[7] = board[7],board[6] elif M == "R": board[7],board[8] = board[8],board[7] elif M == "U": board[4],board[7] = board[7],board[4] elif 0 == board[8]: if M == "U": board[5],board[8] = board[8],board[5] elif M == "L": board[7],board[8] = board[8],board[7] print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) return #------------------------------------------
# 633xxxxx21 612 (2020-09-20 13:21) def print_moves(board, moves): # bonus function: optional N = int((len(board))**0.5) l = 1 v = [] for e in board: v.append(str(e)) while l <= N : u = v[((l-1)*N):(l*N):1] u = ' '.join(u) print(u) l +=1 l = 1 for i in range(len(moves)) : print('------------------------'+ moves[i]) a = board.index(0) if moves[i] =='D': board.remove(0) board.insert(a+N-1,0) g = board.pop(a+N) board.insert(a,g) elif moves[i] =='U': board.remove(0) board.insert(a-N,0) g = board.pop(a-N+1) board.insert(a,g) elif moves[i] =='L': board.remove(0) board.insert(a-1,0) elif moves[i] =='R': board.remove(0) board.insert(a+1,0) v = [] l = 1 for e in board: v.append(str(e)) while l <= N : u = v[((l-1)*N):(l*N):1] u = ' '.join(u) print(u) l +=1 return '' #------------------------------------------
# 633xxxxx21 613 (2020-09-20 22:07) def print_moves(board, moves): # bonus function: optional return # ------------------------------------------ # board = [4, 1, 3, 2, 5, 6, 7, 8, 0] # board = [1, 3, 6, 4, 0, 2, 7, 5, 8]
# 633xxxxx21 614 (2020-09-20 22:35) def print_moves(board, moves): # bonus function: optional print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) for i in range(len(moves)): print("-"*9+moves[i]) pos = board.index(0) if moves[i] == "R": board[pos],board[pos+1]=board[pos+1],board[pos] if moves[i] == "L": board[pos],board[pos-1]=board[pos-1],board[pos] if moves[i] == "D": board[pos],board[pos+3]=board[pos+3],board[pos] if moves[i] == "U": board[pos],board[pos-3]=board[pos-3],board[pos] print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) return
# 633xxxxx21 615 (2020-09-20 22:06) def print_moves(board, moves):# bonus function: optional N = int(len(board)**0.5) for i in range(0,N**2,N): k = i+N-1 while i < k : print(board[i],end=" ") i += 1 print(board[i]) print((N**2-3)*"-"+"U") board1 = [1,2,3,4,5,0,7,8,6] for i in range(0,N**2,N): k = i+N-1 while i < k : print(board1[i],end=" ") i += 1 print(board1[i]) print((N**2-3)*"-"+"L") board2 = [1,2,3,4,0,5,7,8,6] for i in range(0,N**2,N): k = i+N-1 while i < k : print(board2[i],end=" ") i += 1 print(board2[i]) print((N**2-3)*"-"+"D") board3 = [1,2,3,4,8,5,7,0,6] for i in range(0,N**2,N): k = i+N-1 while i < k : print(board3[i],end=" ") i += 1 print(board3[i]) print((N**2-3)*"-"+"R") return #------------------------------------------
# 633xxxxx21 616 (2020-09-19 16:38) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 617 (2020-09-19 11:51) def print_moves(board, moves): # bonus function: optional N = 1 while N*N != len(board): N += 1 for k in range((len(board))): print(str(board[k])+" ", end=" ") if (k+1)%N == 0: print("\n") for i in range(len(moves)): empty = board.index(0) # up if moves[i] == "U": board[empty], board[empty-N] = board[empty-N], board[empty] # down if moves[i] == "D": board[empty], board[empty+N] = board[empty+N], board[empty] # left if moves[i] == "L": board[empty], board[empty-1] = board[empty-1], board[empty] # right if moves[i] == "R": board[empty], board[empty+1] = board[empty+1], board[empty] print("-"*(N*3)+moves[i]) for j in range((len(board))): print(str(board[j])+" ", end=" ") if (j+1)%N == 0: print("\n") #------------------------------------------
# 633xxxxx21 618 (2020-09-20 21:39) def print_moves(board, moves): # bonus function: optional pass #return #------------------------------------------
# 633xxxxx21 619 (2020-09-20 22:52) def print_moves(board, moves): # bonus function: optional N = int((len(board))**(0.5)) for k in board: print(k,'',end='') if board.index(k) == N-1: print('') elif board.index(k) == 2*N-1: print('') elif board.index(k) == 3*N-1: print('') elif board.index(k) == 4*N-1: print('') for i in range(len(moves)): print('---------------'+moves[i]) m = board.index(0) if moves[i]== 'D': board[m],board[m+N] = board[m+N],board[m] elif moves[i]=='R': board[m],board[m+1] = board[m+1],board[m] elif moves[i]=='U': board[m],board[m-N] = board[m-N],board[m] elif moves[i]=='L': board[m],board[m-1] = board[m-1],board[m] for k in board: print(k,'',end='') if board.index(k) == N-1: print('') elif board.index(k) == 2*N-1: print('') elif board.index(k) == 3*N-1: print('') elif board.index(k) == 4*N-1: print('') return #------------------------------------------
# 633xxxxx21 620 (2020-09-20 22:54) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 621 (2020-09-20 19:13) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 622 (2020-09-19 20:20) def print_moves(board, moves): # bonus function: optional pass #return #------------------------------------------
# 633xxxxx21 623 (2020-09-20 15:20) def print_moves(board, moves): # bonus function: optional board =[4, 1, 3, 2, 5, 6, 7, 8, 0] moves = 'LULURDDR' return #------------------------------------------
# 633xxxxx21 624 (2020-09-20 15:01) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 625 (2020-09-19 14:47) def print_moves(board, moves): # bonus function: optional pass #return #------------------------------------------
# 633xxxxx21 626 (2020-09-20 20:57) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 627 (2020-09-20 23:25) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 628 (2020-09-20 21:49) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 629 (2020-09-20 13:08) def print_moves(board, moves): # bonus function: optional pass #return #------------------------------------------
# 633xxxxx21 630 (2020-09-20 23:39) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 631 (2020-09-20 22:16) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 632 (2020-09-19 15:00) def print_moves(board, moves): # bonus function: optional pass #return #------------------------------------------
# 633xxxxx21 633 (2020-09-20 19:26) def print_moves(board, moves): # bonus function: optional pass #return #------------------------------------------
# 633xxxxx21 634 (2020-09-20 12:20) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 635 (2020-09-20 17:54) def print_moves(board, moves): # bonus function: optional board = [1,3,0,4,2,5,7,8,6,'LR'] moves = 'LDRD' print(" 1 3 0 ") return #------------------------------------------
# 633xxxxx21 636 (2020-09-20 20:24) def print_moves(board, moves): # bonus function: optional return #-------------------------------------------
# 633xxxxx21 637 (2020-09-20 20:45) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 638 (2020-09-20 22:23) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 639 (2020-09-20 17:58) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)): print("",board[0],"",board[1],"",board[2]) print("",board[3],"",board[4],"",board[5]) print("",board[6],"",board[7],"",board[8]) print("-------------", moves[i]) y = board.index(0) if moves[i] == "D": board.remove(0) board.insert(y+2,0) board.insert(y,board[y+3]) board.pop(y+4) elif moves[i] == "U": board.remove(0) board.insert(y-3,0) board.insert(y,board[y-2]) board.pop(y-2) elif moves[i] == "R": board.remove(0) board.insert(y+1,0) elif moves[i] == "L": board.remove(0) board.insert(y-1,0) print("",board[0],"",board[1],"",board[2]) print("",board[3],"",board[4],"",board[5]) print("",board[6],"",board[7],"",board[8]) return #------------------------------------------
# 633xxxxx21 640 (2020-09-20 23:22) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)) : print(' ',board[0],' ',board[1],' ',board[2]) print(' ',board[3],' ',board[4],' ',board[5]) print(' ',board[6],' ',board[7],' ',board[8]) print('---------', moves[i]) y = board.index(0) if moves[i] == 'U' : board.remove(0) board.insert(y-3,0) board.insert(y+1,board[y-2]) board.pop(y-2) elif moves[i] == 'D' : board.remove(0) board.insert(y+2,0) board.insert(y,board[y+3]) board.pop(y+4) elif moves[i] == 'L' : board.remove(0) board.insert(y-1,0) elif moves[i] == 'R' : board.remove(0) board.insert(y+1,0) print(' ',board[0],' ',board[1],' ',board[2]) print(' ',board[3],' ',board[4],' ',board[5]) print(' ',board[6],' ',board[7],' ',board[8]) return #------------------------------------------
# 633xxxxx21 641 (2020-09-20 21:43) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)): for g in range(0,8,3): print('',board[g],'',board[g+1],'',board[g+2]) print('---------',moves[i]) w = board.index(0) if moves[i] == 'U' : board.remove(0) ; board.insert(w-3,0) board.insert(w+1,board[w-2]) ; board.pop(w-2) elif moves[i] == 'D' : board.remove(0) ; board.insert(w+2,0) board.insert(w,board[w+3]) ; board.pop(w+4) elif moves[i] == 'L' : board.remove(0) ; board.insert(w-1,0) else : board.remove(0) ; board.insert(w+1,0) for g in range(0,8,3): print('',board[g],'',board[g+1],'',board[g+2]) return #------------------------------------------
# 633xxxxx21 642 (2020-09-20 23:27) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)): print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print('---------', moves[i]) b = board.index(0) if moves[i] == 'D' : board.remove(0) board.insert(b+2,0) board.insert(b,board[b+3]) board.pop(b+4) elif moves[i] == 'L' : board.remove(0) board.insert(b-1,0) elif moves[i] == 'R' : board.remove(0) board.insert(b+1,0) elif moves[i] == 'U' : board.remove(0) board.insert(b-3,0) board.insert(b+1,board[b-2]) board.pop(b-2) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 643 (2020-09-20 01:38) def print_moves(board, moves): for i in range(len(moves)) : print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print('---------', moves[i]) q = board.index(0) if moves[i] == 'R' : board.remove(0) board.insert(q+1,0) elif moves[i] == 'L' : board.remove(0) board.insert(q-1,0) elif moves[i] == 'D' : board.remove(0) board.insert(q+2,0) board.insert(q,board[q+3]) board.pop(q+4) elif moves[i] == 'U' : board.remove(0) board.insert(q-3,0) board.insert(q+1,board[q-2]) board.pop(q-2) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 644 (2020-09-20 18:36) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 645 (2020-09-17 04:04) def print_moves(board, moves): for i in range(len(moves)): print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print('---------', moves[i]) b = board.index(0) if moves[i] == 'D' : board.remove(0) board.insert(b+2,0) board.insert(b,board[b+3]) board.pop(b+4) elif moves[i] == 'L' : board.remove(0) board.insert(b-1,0) elif moves[i] == 'R' : board.remove(0) board.insert(b+1,0) elif moves[i] == 'U' : board.remove(0) board.insert(b-3,0) board.insert(b+1,board[b-2]) board.pop(b-2) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 646 (2020-09-20 20:52) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)) : print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print('---------',moves[i]) n = board.index(0) if moves[i] == 'D' : board.remove(0) board.insert(n+2,0) board.insert(n,board[n+3]) board.pop(n+4) elif moves[i] == 'L' : board.remove(0) board.insert(n-1,0) elif moves[i] == 'R' : board.remove(0) board.insert(n+1,0) elif moves[i] == 'U' : board.remove(0) board.insert(n-3,0) board.insert(n+1,board[n-2]) board.pop(n-2) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 647 (2020-09-19 14:32) def print_moves(board, moves): board = [1,2,3,4,6,0,7,5,8] moves = 'LDR' return #------------------------------------------
# 633xxxxx21 648 (2020-09-20 22:19) def print_moves(board,moves): for i in range(len(moves)): print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print("---------",moves[i]) j = board.index(0) if moves[i] == "U": board.remove(0) board.insert(j-3,0) board.insert(j+1,board[j-2]) board.pop(j-2) elif moves[i] == "D": board.remove(0) board.insert(j+2,0) board.insert(j,board[j+3]) board.pop(j+4) elif moves[i] == "R": board.remove(0) board.insert(j+1,0) elif moves[i] == "L": board.remove(0) board.insert(j-1,0) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 649 (2020-09-20 20:46) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 650 (2020-09-20 17:46) def print_moves(board, moves): return #------------------------------------------
# 633xxxxx21 651 (2020-09-20 23:13) def print_moves(board, moves): for i in range(len(moves)): print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print('---------', moves[i]) x = board.index(0) if moves[i] == 'D': board = board[:x] + board[x+3:x+4] + board[x+1:x+3] + board[x:x+1] + board[x+4:len(board)] elif moves[i] == 'U': board = board[:x-3] + board[x:x+1] + board[x-2:x] + board[x-3:x-2] + board[x+1:len(board)] elif moves[i] == 'L': board = board[:x-1] + board[x:x+1] + board[x-1:x] + board[x+1:len(board)] elif moves[i] == 'R': board = board[:x] + board[x+1:x+2] + board[x:x+1] + board[x+2:len(board)] else: pass print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 652 (2020-09-17 17:58) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 653 (2020-09-20 13:52) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)): print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print('---------',moves[i]) b = board.index(0) if moves[i] == 'D' : board.remove(0) board.insert(b+2,0) board.insert(b,board[b+3]) board.pop(b+4) elif moves[i] == 'L' : board.remove(0) board.insert(b-1,0) elif moves[i] == 'R' : board.remove(0) board.insert(b+1,0) elif moves[i] == 'U': board.remove(0) board.insert(b-3,0) board.insert(b+1,board[b-2]) board.pop(b-2) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 654 (2020-09-20 16:28) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)): print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print('----------------------',moves[i]) b = board.index(0) if moves[i] == 'U' : board.remove(0) board.insert(b-3,0) board.insert(b+1,board[b-2]) board.pop(b-2) elif moves[i] == "D": board.remove(0) board.insert(b+2,0) board.insert(b,board[b+3]) board.pop(b+4) elif i == 'L': board.remove(0) board.insert(b-1,0) elif i == "R": board.remove(0) board.insert(b+1,0) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 655 (2020-09-20 23:51) def print_moves(board, moves): N = len(board) n = int(len(board)**0.5) for j in range(len(board)): print(board[j],end=" ") if (j+1)%n==0: print() for i in range(len(moves)): z = board.index(0) if moves[i] == "D": board[z],board[z+n]=board[z+n],board[z] if moves[i] == "U": board[z],board[z-n]=board[z-n],board[z] if moves[i] == "L": board[z],board[z-1]=board[z-1],board[z] if moves[i] == "R": board[z],board[z+1]=board[z+1],board[z] print("---------",moves[i]) for j in range(len(board)): print(board[j],end=" ") if (j+1)%n==0: print() return #------------------------------------------
# 633xxxxx21 656 (2020-09-20 22:06) def print_moves(board, moves): # bonus function: optional n = int((len(board))**(1/2)) for i in range(n): line = '' for j in range(n): line += str(board[i*n + j])+' ' print(line) for i in moves: x = board.index(0) print('---------',i) if i == 'U': board[x],board[x-n]=board[x-n],board[x] elif i == 'D': board[x],board[x+n]=board[x+n],board[x] elif i =='L': board[x],board[x-1]=board[x-1],board[x] else: board[x],board[x+1]=board[x+1],board[x] for i in range(n): line = '' for j in range(n): line += str(board[i*n + j])+' ' print(line) return #------------------------------------------
# 633xxxxx21 657 (2020-09-20 16:40) def print_moves(board, moves): # bonus function: optional for i in range(len(moves)): print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) print('---------',moves[i]) b = board.index(0) if moves[i] == 'D' : board.remove(0) board.insert(b+2,0) board.insert(b,board[b+3]) board.pop(b+4) elif moves[i] == 'L' : board.remove(0) board.insert(b-1,0) elif moves[i] == 'R' : board.remove(0) board.insert(b+1,0) elif moves[i] == 'U': board.remove(0) board.insert(b-3,0) board.insert(b+1,board[b-2]) board.pop(b-2) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return #------------------------------------------
# 633xxxxx21 658 (2020-09-19 23:32) def print_moves(board, moves): n=len(board)**(1/2) a='' i=0 while i<len(board)+1: if i%n==0 and i!=0: print(' '+a) a='' if i==len(board): break a +=str(board[i]) elif i==0: a +=str(board[i]) else: a +=' '+str(board[i]) i +=1 n=int(len(board)**(1/2)) x=[] x +=board for i in moves: if i == 'R': print('---------','R') b=x.index(0) x[b]=x[b+1] x[b+1]=0 a='' i=0 while i<len(board)+1: if i%n==0 and i!=0: print(' '+a) a='' if i==len(x): break a +=str(x[i]) elif i==0: a +=str(x[i]) else: a +=' '+str(x[i]) i +=1 elif i == 'U': print('---------','U') b=x.index(0) x[b]=x[b-n] x[b-n]=0 a='' i=0 while i<len(x)+1: if i%n==0 and i!=0: print(' '+a) a='' if i==len(board): break a +=str(x[i]) elif i==0: a +=str(x[i]) else: a +=' '+str(x[i]) i +=1 elif i == 'D': print('---------','D') b=x.index(0) x[b]=x[b+n] x[b+n]=0 a='' i=0 while i<len(x)+1: if i%n==0 and i!=0: print(' '+a) a='' if i==len(x): break a +=str(x[i]) elif i==0: a +=str(x[i]) else: a +=' '+str(x[i]) i +=1 elif i == 'L': print('---------','L') b=x.index(0) x[b]=x[b-1] x[b-1]=0 a='' i=0 while i<len(x)+1: if i%n==0 and i!=0: print(' '+a) a='' if i==len(x): break a +=str(x[i]) elif i==0: a +=str(x[i]) else: a +=' '+str(x[i]) i +=1 return #------------------------------------------
# 633xxxxx21 659 (2020-09-20 21:52) def print_moves(board, moves): # bonus function: optional print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) for i in moves: index = board.index(0) if i == "U": temp = board[index - 3] board[index - 3] = board[index] board[index] = temp elif i == "D": temp = board[index + 3] board[index + 3] = board[index] board[index] = temp elif i == "L": temp = board[index - 1] board[index - 1] = board[index] board[index] = temp elif i == "R": temp = board[index + 1] board[index + 1] = board[index] board[index] = temp print("------" + i) print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) return #------------------------------------------
# 633xxxxx21 660 (2020-09-20 23:50) def print_moves(board, moves): for e in moves : idx = board.index(0) if e == 'U' : board[idx], board[idx-3] = board[idx-3], board[idx] elif e == 'D' : board[idx], board[idx+3] = board[idx+3], board[idx] elif e == 'L' : board[idx], board[idx-1] = board[idx-1], board[idx] elif e == 'R' : board[idx], board[idx+1] = board[idx+1], board[idx] printBoard(board) print('\n--------- ' + e) return #------------------------------------------ def printBoard(board) : for i in range(len(board)) : if i % 3 == 0 and i != 0 : print('') print(board[i], end=' ')
# 633xxxxx21 661 (2020-09-20 17:40) def print_moves (board, moves): # bonus function: optional for i in range(len(moves)): print('',board[0],'' ,board[1],'',board[2]) print('',board[3],'' ,board[4],'',board[5]) print('',board[6],'' ,board[7],'',board[8]) print('=-=-=-=-=-=-=-=', moves[i]) A = board.index(0) if moves[i] == 'D' : board.remove (0) board.insert (A+2,0) board.insert (A,board[A+3] ) board.pop (A+4) elif moves[i] == 'L' : board.remove (0) board.insert (A-1,0) elif moves[i] == 'R' : board.remove (0) board.insert (A+1,0) elif moves[i] == 'U' : board.remove (0) board.insert (A-3,0) board.insert (A+1 ,board[A-2]) board.pop(A-2) print('',board[0],'',board[1],'',board[2]) print('',board[3],'',board[4],'',board[5]) print('',board[6],'',board[7],'',board[8]) return # ------------------------------------------
# 633xxxxx21 662 (2020-09-20 23:36) def print_moves(board, moves): for e in moves : idx = board.index(0) if e == 'U' : board[idx], board[idx-3] = board[idx-3], board[idx] elif e == 'D' : board[idx], board[idx+3] = board[idx+3], board[idx] elif e == 'L' : board[idx], board[idx-1] = board[idx-1], board[idx] elif e == 'R' : board[idx], board[idx+1] = board[idx+1], board[idx] printBoard(board) print('\n--------- ' + e) return #------------------------------------------ def printBoard(board) : for i in range(len(board)) : if i % 3 == 0 and i != 0 : print('') print(board[i], end=' ')
# 633xxxxx21 663 (2020-09-20 23:15) def print_moves(board, moves): print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) for i in moves: index = board.index(0) if i == "U": temp = board[index - 3] board[index - 3] = board[index] board[index] = temp elif i == "D": temp = board[index + 3] board[index + 3] = board[index] board[index] = temp elif i == "L": temp = board[index - 1] board[index - 1] = board[index] board[index] = temp elif i == "R": temp = board[index + 1] board[index + 1] = board[index] board[index] = temp print("------" + i) print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) return #------------------------------------------
# 633xxxxx21 664 (2020-09-20 23:10) def print_moves(board, moves): # bonus function: optional print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) for i in moves: index = board.index(0) if i == "U": temp = board[index - 3] board[index - 3] = board[index] board[index] = temp elif i == "D": temp = board[index + 3] board[index + 3] = board[index] board[index] = temp elif i == "L": temp = board[index - 1] board[index - 1] = board[index] board[index] = temp elif i == "R": temp = board[index + 1] board[index + 1] = board[index] board[index] = temp print("------" + i) print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) return #------------------------------------------
# 633xxxxx21 665 (2020-09-20 22:57) def print_moves(board, moves): # bonus function: optional blank = board.index(0) node = board print(node[0], node[1], node[2]) print(node[3], node[4], node[5]) print(node[6], node[7], node[8]) for m in moves: if (m == 'U'): if blank not in [0,1,2]: node[blank], node[blank-3] = node[blank-3], node[blank] blank = node.index(0) elif (m == 'D'): if blank not in [6,7,8]: node[blank], node[blank+3] = node[blank+3], node[blank] blank = node.index(0) elif (m == 'R'): if blank not in [2,5,8]: node[blank], node[blank+1] = node[blank+1], node[blank] blank = node.index(0) elif (m == 'L'): if blank not in [0,3,6]: node[blank], node[blank-1] = node[blank-1], node[blank] blank = node.index(0) print("--------- "+m) print(node[0], node[1], node[2]) print(node[3], node[4], node[5]) print(node[6], node[7], node[8]) return #------------------------------------------
# 633xxxxx21 666 (2020-09-20 20:14) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 667 (2020-09-20 13:55) def print_moves(board, moves): # bonus function: optional size=int(len(board)**(1/2)) i = 0 while i<len(board) : out="" for j in range (0,size) : out+= str(board[i])+" " i+=1 print(out) for e in moves : print("--------- "+e) position=board.index(0) if e == "R" : board[position],board[position+1]=board[position+1],board[position] elif e == "L" : board[position-1],board[position]=board[position],board[position-1] elif e == "U" : board[position-size],board[position]=board[position],board[position-size] elif e == "D" : board[position],board[position+size]=board[position+size],board[position] i = 0 while i<len(board) : out="" for j in range (0,size) : out+= str(board[i])+" " i+=1 print(out) return #------------------------------------------
# 633xxxxx21 668 (2020-09-19 23:31) def print_moves(board, moves): # bonus function: optional size=int(len(board)**(1/2)) i = 0 while i<len(board) : out="" for j in range (0,size) : out+= str(board[i])+" " i+=1 print(out) for e in moves : print("--------- "+e) position=board.index(0) if e == "R" : board[position],board[position+1]=board[position+1],board[position] elif e == "L" : board[position-1],board[position]=board[position],board[position-1] elif e == "U" : board[position-size],board[position]=board[position],board[position-size] elif e == "D" : board[position],board[position+size]=board[position+size],board[position] i = 0 while i<len(board) : out="" for j in range (0,size) : out+= str(board[i])+" " i+=1 print(out) return #------------------------------------------
# 633xxxxx21 669 (2020-09-20 14:29) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 670 (2020-09-20 21:34) def print_moves(board, moves): # bonus function: optional pass #------------------------------------------
# 633xxxxx21 671 (2020-09-20 23:05) def print_moves(board, moves): print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) for i in moves: index = board.index(0) if i == "U": temp = board[index - 3] board[index - 3] = board[index] board[index] = temp elif i == "D": temp = board[index + 3] board[index + 3] = board[index] board[index] = temp elif i == "L": temp = board[index - 1] board[index - 1] = board[index] board[index] = temp elif i == "R": temp = board[index + 1] board[index + 1] = board[index] board[index] = temp print("------" + i) print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) return #------------------------------------------
# 633xxxxx21 672 (2020-09-20 23:39) def print_moves(board, moves): # bonus function: optional return # ------------------------------------------
# 633xxxxx21 673 (2020-09-20 23:58) def print_moves(board, moves): # bonus function: optional board=[str(e) for e in board] n=int(len(board)**0.5) for i in range (0,len(board),n): print(' '.join(board[i:i+n])) for e in moves: print("---------",e) if '0' in board: u = board.index('0') if e =='U': board[u],board[u-n]=board[u-n],board[u] elif e =='D': board[u],board[u+n]=board[u+n],board[u] elif e =='R': board[u],board[u+1]=board[u+1],board[u] elif e =='L': board[u],board[u-1]=board[u-1],board[u] for i in range (0,len(board),n): print(' '.join(board[i:i+n])) return #------------------------------------------
# 633xxxxx21 674 (2020-09-20 21:47) def print_moves(board, moves): # bonus function: optional def arrange(board): for i in board: if board.index(i) in [0,3,6]: print((' '+str(i)),end='') if board.index(i) in [1,4,7]: print((' '+str(i)),end='') if board.index(i) in [2,5,8]: print(' '+str(i)) arrange(board) for e in range(len(moves)): print('-'*9,moves[e]) s=[] i=board.index(0) if moves[e]=='U': board=board[:i-3]+[board[i]]+board[i-2:i]+[board[i-3]]+board[i+1:] if moves[e]=='D': board=board[:i]+[board[i+3]]+board[i+1:i+3]+[board[i]]+board[i+4:] if moves[e]=='R': board=board[:i]+[board[i+1]]+[board[i]]+board[i+2:] if moves[e]=='L': board=board[:i-1]+[board[i]]+[board[i-1]]+board[i+1:] arrange(board) return #------------------------------------------
# 633xxxxx21 675 (2020-09-20 18:23) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 676 (2020-09-19 12:26) def print_moves(board, moves): return #------------------------------------------ #board = [4,1,3,2,5,6,7,8,0] #board = [1,3,6,4,0,2,7,5,8] #board = [2,3,6,0,1,5,4,7,8]
# 633xxxxx21 677 (2020-09-20 02:55) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 678 (2020-09-20 22:50) def print_moves(board, moves): board = [1,5,0,2,4,3,7,8,6] moves = 'DLLURDRULLDRURDD' # bonus function: optional return #------------------------------------------
# 633xxxxx21 679 (2020-09-20 19:31) def print_moves(board, moves): # bonus function: optional n = len(board) N =2 while True: if(N**2==n): break N+=1 for i in(moves): m = board.index(0) if i == 'L': board[m] = board[m-1] board[m-1] = 0 elif i == 'D': board[m] = board[m+3] board[m+3] = 0 elif i =='R': board[m] = board[m+1] board[m+1] = 0 elif i =='U': board[m] = board[m-3] board[m-3] = 0 for j in(board): print(j,end=" ") if((board.index(j)+1)%N==0): print() print("--------- %s"%(i)) return #------------------------------------------
# 633xxxxx21 680 (2020-09-20 16:04) def print_moves(board, moves): # bonus function: optional b = list(board) k = 0 h=int(len(board)**(0.5)) A=0 while A < h: for i in range(1,h+1): print(b[i-1+h*A],end=' ') print('') A += 1 while k < len(moves): t=b.index(0) if moves[k] == 'U': b[t],b[t-h] = b[t-h],b[t] elif moves[k] =='D': b[t],b[t+h] = b[t+h],b[t] elif moves[k] =='L': b[t],b[t-1] = b[t-1],b[t] elif moves[k] =='R': b[t],b[t+1] = b[t+1],b[t] print('---------'+moves[k]) A=0 while A < h: for i in range(1,h+1): print(b[i-1+h*A],end=' ') print('') A += 1 k +=1 return #------------------------------------------
# 633xxxxx21 681 (2020-09-20 21:41) def print_moves(board, moves): # bonus function: optional n = len(board) N =2 while True: if(N**2==n): break N+=1 for i in(moves): m=board.index(0) if i=='L': board[m]=board[m-1] board[m-1]=0 elif i=='D': board[m]=board[m+3] board[m+3]=0 elif i=='R': board[m]=board[m+1] board[m+1]=0 elif i=='U': board[m]=board[m-3] board[m-3]=0 for j in(board): print(j,end=" ") if((board.index(j)+1)%N==0): print() print("--------- %s"%(i)) return #------------------------------------------
# 633xxxxx21 682 (2020-09-20 20:40) def print_moves(board, moves): # bonus function: optional return #------------------------------------------
# 633xxxxx21 683 (2020-09-20 16:03) def print_moves(board, moves): print( ) print(' '+str(board[0])+' '+str(board[1])+' '+str(board[2])) print(' '+str(board[3])+' '+str(board[4])+' '+str(board[5])) print(' '+str(board[6])+' '+str(board[7])+' '+str(board[8])) for x in moves: if x == 'D': b = board.index(0) board[b],board[b+3] = board[b+3],board[b] print('---------',x) print(' '+str(board[0])+' '+str(board[1])+' '+str(board[2])) print(' '+str(board[3])+' '+str(board[4])+' '+str(board[5])) print(' '+str(board[6])+' '+str(board[7])+' '+str(board[8])) elif x == 'L': b = board.index(0) board[b],board[b-1] = board[b-1],board[b] print('---------',x) print(' '+str(board[0])+' '+str(board[1])+' '+str(board[2])) print(' '+str(board[3])+' '+str(board[4])+' '+str(board[5])) print(' '+str(board[6])+' '+str(board[7])+' '+str(board[8])) elif x == 'U': b = board.index(0) board[b],board[b-3] = board[b-3],board[b] print('---------',x) print(' '+str(board[0])+' '+str(board[1])+' '+str(board[2])) print(' '+str(board[3])+' '+str(board[4])+' '+str(board[5])) print(' '+str(board[6])+' '+str(board[7])+' '+str(board[8])) elif x == 'R': b = board.index(0) board[b],board[b+1] = board[b+1],board[b] print('---------',x) print(' '+str(board[0])+' '+str(board[1])+' '+str(board[2])) print(' '+str(board[3])+' '+str(board[4])+' '+str(board[5])) print(' '+str(board[6])+' '+str(board[7])+' '+str(board[8])) return #------------------------------------------
# 633xxxxx21 684 (2020-09-20 22:29) def print_moves(board, moves): # bonus function: optional for i in moves: ตำแหน่ง=board.index(0) print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) if i=='L': board[ตำแหน่ง],board[ตำแหน่ง-1]=board[ตำแหน่ง-1],board[ตำแหน่ง] print('-------------L') elif i=='R': board[ตำแหน่ง],board[ตำแหน่ง+1]=board[ตำแหน่ง+1],board[ตำแหน่ง] print('-------------R') elif i=='U': board[ตำแหน่ง],board[ตำแหน่ง-3]=board[ตำแหน่ง-3],board[ตำแหน่ง] print('-------------U') elif i=='D': board[ตำแหน่ง],board[ตำแหน่ง+3]=board[ตำแหน่ง+3],board[ตำแหน่ง] print('-------------D') print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) return #------------------------------------------
# 633xxxxx21 685 (2020-09-20 21:47) def print_moves(board, moves): # bonus function: optional print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) for i in moves: index = board.index(0) if i == "U": temp = board[index - 3] board[index - 3] = board[index] board[index] = temp elif i == "D": temp = board[index + 3] board[index + 3] = board[index] board[index] = temp elif i == "L": temp = board[index - 1] board[index - 1] = board[index] board[index] = temp elif i == "R": temp = board[index + 1] board[index + 1] = board[index] board[index] = temp print("------" + i) print(board[0], board[1], board[2]) print(board[3], board[4], board[5]) print(board[6], board[7], board[8]) return #------------------------------------------
# 633xxxxx21 686 (2020-09-20 02:21) def print_moves(board, moves): # bonus function: optional print(board[0],board[1],board[2]) print(board[3],board[4],board[5]) print(board[6],board[7],board[8]) X=board[:] for i in range(len(moves)): print('---------',moves[i]) ZERO = X.index(0) if moves[i] == 'L': X[ZERO],X[ZERO-1] = X[ZERO-1],X[ZERO] elif moves[i] == 'R': X[ZERO],X[ZERO+1] = X[ZERO+1],X[ZERO] elif moves[i] == 'D': X[ZERO],X[ZERO+3] = X[ZERO+3],X[ZERO] elif moves[i] == 'U': X[ZERO],X[ZERO-3] = X[ZERO-3],X[ZERO] print(X[0],X[1],X[2]) print(X[3],X[4],X[5]) print(X[6],X[7],X[8]) return #------------------------------------------
# 633xxxxx21 687 (2020-09-20 12:27) def print_moves(board, moves): # bonus function: optional board1 = list(board) board1 += 'S' n = check_N(board1) for e in moves: for i in range(0,len(board1[:-1]),n): print(' '+str(board1[i])+' '+str(board1[i+1])+' '+str(board1[i+2])) print('---------',e) if e == 'U': U = Up_0(board1) board1 = U elif e == 'D': D = Down_0(board1) board1 = D elif e == 'R': R = Right_0(board1) board1 = R elif e == 'L': L = Left_0(board1) board1 = L for i in range(0,len(board1[:-1]),n): print(' '+str(board1[i])+' '+str(board1[i+1])+' '+str(board1[i+2])) return #------------------------------------------ def check_N(node): N = int((len(node[:-1]))**(1/2)) return N def Left_0(d): x = d.index(0) d1 = list(d) d1[x],d1[x-1] = d1[x-1],d1[x] d1[-1] += 'L' return d1 def Down_0(d): n = check_N(d) x = d.index(0) d1 = list(d) if x < n**2-n: d1[x],d1[x+n] = d1[x+n],d1[x] d1[-1] += 'D' return d1 def check_N(node): N = int((len(node[:-1]))**(1/2)) return N def Right_0(d): x = d.index(0) d1 = list(d) d1[x],d1[x+1] = d1[x+1],d1[x] d1[-1] += 'R' return d1 def Up_0(d): n = check_N(d) x = d.index(0) d1 = list(d) d1[x],d1[x-n] = d1[x-n],d1[x] d1[-1] += 'U' return d1 def check_N(node): N = int((len(node[:-1]))**(1/2)) return N
# 633xxxxx21 688 (2020-09-20 20:08) def print_moves(board, moves): f = [] f[:] = board x = int((len(board))**(0.5)) for i in range(0,x**2,x): h = [] g = f[i:i+x] for e in g: h.append(str(e)) print(' '.join(h)) for e in moves: p = f.index(0) if e == 'D': f[p],f[p+x] = f[p+x], f[p] elif e == 'U': f[p],f[p-x] = f[p-x], f[p] elif e == 'L': f[p],f[p-1] = f[p-1], f[p] elif e == 'R': f[p],f[p+1] = f[p+1], f[p] print('---------',e) for i in range(0,x**2,x): h = [] g = f[i:i+x] for e in g: h.append(str(e)) print(' '.join(h)) return #------------------------------------------
# 633xxxxx21 689 (2020-09-20 19:39) def print_moves(board, moves): # bonus function: optional l = len(board) ln = int(l**0.5) for i in range(ln): p = [] for j in range(ln): p.append(str(board[ln*i+j])) print(' '+' '.join(p)) for m in moves: n = board.index(0) x = m if m == 'U': board[n], board[n-ln] = board[n-ln], 0 elif m == 'D': board[n], board[n+ln] = board[n+ln], 0 elif m == 'L': board[n], board[n-1] = board[n-1], 0 elif m == 'R': board[n], board[n+1] = board[n+1], 0 print('-'*3*ln+' '+x) for i in range(ln): p = [] for j in range(ln): p.append(str(board[ln*i+j])) print(' '+' '.join(p)) return #------------------------------------------
# 633xxxxx21 690 (2020-09-18 20:10) def print_moves(board, moves): # bonus function: optional N = int(len(board)**0.5) board = [str(e) for e in board] for e in moves : for j in range (N) : print(' '+' '.join(board[j*N:(j+1)*N])) i = board.index('0') if e == 'L' : board[i],board[i-1] = board[i-1],board[i] if e == 'R' : board[i],board[i+1] = board[i+1],board[i] if e == 'U' : board[i],board[i-N] = board[i-N],board[i] if e == 'D' : board[i],board[i+N] = board[i+N],board[i] print('---------',e) for j in range (N) : print(' '+' '.join(board[j*N:(j+1)*N])) return #------------------------------------------
# 633xxxxx21 691 (2020-09-20 03:07) def print_moves(board, moves): # bonus function: optional def printBoard(boardData): for i in range(len(boardData)): print("",boardData[i],"",end="") if i%N==N-1:print() tmp=list(board) N=int(len(tmp)**0.5) printBoard(tmp) for move in moves: print("--------- "+move) zeroIdx=tmp.index(0) if (move=="U"): tmp[zeroIdx],tmp[zeroIdx-N]=tmp[zeroIdx-N],tmp[zeroIdx] elif (move=="D"): tmp[zeroIdx],tmp[zeroIdx+N]=tmp[zeroIdx+N],tmp[zeroIdx] elif (move=="L"): tmp[zeroIdx],tmp[zeroIdx-1]=tmp[zeroIdx-1],tmp[zeroIdx] elif (move=="R"): tmp[zeroIdx],tmp[zeroIdx+1]=tmp[zeroIdx+1],tmp[zeroIdx] printBoard(tmp) return #------------------------------------------
# 633xxxxx21 692 (2020-09-20 16:43) def print_moves(board, moves): # bonus function: optional N=int(len(board)**0.5) b1=[str(e) for e in board] b2=board j=0 def twostr(e): if len(e)==1: return e+' ' return e for i in range(N): e21=[twostr(e2) for e2 in b1[j:j+N]] print(' '+' '.join(e21)) j+=N for u in moves: j=0 print('-'*(N*3)+' '+u) i=board.index(0) if u=='U': b2[i],b2[i-N]=b2[i-N],b2[i] elif u=='D': b2[i],b2[i+N]=b2[i+N],b2[i] elif u=='L': b2[i],b2[i-1]=b2[i-1],b2[i] elif u=='R': b2[i],b2[i+1]=b2[i+1],b2[i] b3=[str(ei) for ei in b2] for i in range(N): e23=[twostr(e2) for e2 in b3[j:j+N]] print(' '+' '.join(e23)) j+=N return #------------------------------------------
# 633xxxxx21 693 (2020-09-19 20:16) def print_moves(board, moves): # bonus function: optional lm = len(moves) x = list(board) N = int((len(board))**0.5) i0 = x.index(0) for j in range (N): for k in range (N-1): print (" "+str(x[N*j+k])+" ",end="") print (" "+str(x[N*j+N-1])+" ") for i in range (lm): if moves[i] == "U": i = x.pop(i0-N) x.remove(0) x.insert(i0-N,0) x.insert(i0,i) print("-"*3*N+"U") for j in range (N): for k in range (N-1): print (" "+str(x[N*j+k])+" ",end="") print (" "+str(x[N*j+N-1])+" ") elif moves[i] == "D": i = x.pop(N+i0) x.insert(N+i0,0) x.remove(0) x.insert(i0,i) print("-"*3*N+"D") for j in range (N): for k in range (N-1): print (" "+str(x[N*j+k])+" ",end="") print (" "+str(x[N*j+N-1])+" ") elif moves[i] == "L": i = x.pop(i0-1) x.insert(i0-1,0) x.remove(0) x.insert(i0,i) print("-"*3*N+"L") for j in range (N): for k in range (N-1): print (" "+str(x[N*j+k])+" ",end="") print (" "+str(x[N*j+N-1])+" ") elif moves[i] == "R": i = x.pop(i0+1) x.insert(i0+1,0) x.remove(0) x.insert(i0,i) print("-"*3*N+"R") for j in range (N): for k in range (N-1): print (" "+str(x[N*j+k])+" ",end="") print (" "+str(x[N*j+N-1])+" ") i0 = x.index(0) return #------------------------------------------
# 633xxxxx21 694 (2020-09-18 16:20) def print_moves(board, moves): # bonus function: optional #print board N=int((len(board)**0.5)) for e in range(N): for i in range(N): if i<N-1: print(board[e*N+i],end=" ") else: print(board[e*N+i]) for a in range(0,len(moves)): print("----------",moves[a]) indx=board.index(0) x=board if moves[a]=="U": x[indx],x[indx-N]=x[indx-N],x[indx] board=x elif moves[a]=="D": x[indx],x[indx+N]=x[indx+N],x[indx] board=x elif moves[a]=="R": x[indx],x[indx+1]=x[indx+1],x[indx] board=x else: x[indx],x[indx-1]=x[indx-1],x[indx] board=x for e in range(N): for i in range(N): if i<N-1: print(board[e*N+i],end=" ") else: print(board[e*N+i]) return #------------------------------------------
# 633xxxxx21 695 (2020-09-20 21:34) def print_moves(board, moves): N = int((len(board))**0.5) # bonus function: optional a=[] for i in range(0,len(board),N): a.append(board[i:i+N:]) for i in range(0,N,1): b = "" for j in range(0,N,1): if len(str(a[i][j])) == 1 : b += " " + str(a[i][j]) + " " elif len(str(a[i][j])) == 2 : b += " " + str(a[i][j]) print(b) if len(moves) != 0 : for e in moves: c=[] w = board.index(0) print("-"*len(b) + " " + e ) if e == "U" : board[w-N],board[w] = board[w],board[w-N] elif e == "D" : board[w+N],board[w] = board[w],board[w+N] elif e == "L" : board[w-1],board[w] = board[w],board[w-1] elif e == "R" : board[w+1],board[w] = board[w],board[w+1] for i in range(0,len(board),N): c.append(board[i:i+N:]) for i in range(0,N,1): v = "" for j in range(0,N,1): if len(str(c[i][j])) == 1: v += " " + str(c[i][j]) + " " elif len(str(c[i][j])) == 2 : v += " " + str(c[i][j]) print(v) return #------------------------------------------