Advertisement
Guest User

Untitled

a guest
May 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. def gravitation(rows):
  2.  
  3. def checkMotless(rows):
  4. #returns needed steps until column becomes motionless
  5. motless = []
  6. bedrock = len(rows)-1
  7. for i in range(len(rows[0])):
  8. topind = 0
  9. botind = bedrock
  10.  
  11. count = 0
  12.  
  13. topLock = False
  14. botLock = False
  15.  
  16. while not (topLock and botLock):
  17. if rows[botind][i] == '#':
  18. botind = botind - 1
  19. if rows[botind][i] == '.':
  20. botLock = True
  21. if rows[topind][i] == '.':
  22. topind = topind + 1
  23. if rows[topind][i] == '#':
  24. topLock = True
  25. if botind == topind:
  26. topLock = True
  27. botLock = True
  28.  
  29. print(topind)
  30. print(botind)
  31. print("--")
  32. for k in range(topind+1,botind+1,1):
  33. if rows[k][i] == '.':
  34. count = count + 1
  35.  
  36. motless.append(count)
  37. return motless
  38.  
  39.  
  40. motless = checkMotless(rows)
  41.  
  42. print(motless)
  43.  
  44. ans = []
  45. mini = min(motless)
  46.  
  47. for i in range(len(motless)):
  48. if motless[i]==mini:
  49. ans.append(i)
  50.  
  51. return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement