Guest User

Untitled

a guest
Jul 11th, 2019
213
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import math
  3.  
  4. def clearBoard(n):
  5. b=[]
  6. for i in range(n):
  7. t=[]
  8. for j in range(n):
  9. t.append(0)
  10. b.append(t)
  11. return b
  12. def tryBacktrack(i,x,y,q,board,n):
  13. k=-1
  14. q1=False
  15.  
  16. for t in board:
  17. if n**2 in t:
  18. print(board)
  19. return
  20. if i>(n**2):
  21. print("FUCK THAT")
  22. #print(board)
  23. return
  24. #print(board)
  25. while q1 is False and k<7:
  26. k+=1
  27. q1=False
  28. dx=[2,1,-1,-2,-2,-1,1,2]
  29. dy=[1,2,2,1,-1,-2,-2,-1]
  30. u=x+dx[k]
  31. v=y+dy[k]
  32. if u>=0 and u<n and v>=0 and v<n and board[u][v]==0:
  33. if board[u][v]==0:
  34. board[u][v]=i
  35. if i<=(n**2):
  36. tryBacktrack(i+1, u,v,q1,board,n)
  37. if not q1: board[u][v]=0
  38. else:
  39. q1=True
  40. q=q1
  41. #return board
  42. def knightTour(i,j,n,board,done=True):
  43. board[i][j]=1
  44. #return board
  45. tryBacktrack(2,i,j,done,board,n)
  46. board=clearBoard(6)
  47. board2=knightTour(0,0,6,board)
  48. print(board2)
RAW Paste Data