Guest User

Untitled

a guest
Jun 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. up= 1
  2. down = -1
  3. Noclick = 0
  4. clickStatus =[0,0,0,0,0,0,0,0]
  5. stopSequence = []
  6. liftAt = 0
  7. liftStatus = up
  8. stop = False
  9. # the required variables for the operation of lift are now set-up
  10. def callLift(direction,floor,clickStatus):
  11. clickStatus[floor] = direction
  12. def hasElement(list,ele):
  13. flag = False
  14. for i in range(0,len(list)-1):
  15. if(list[i] == ele):
  16. flag = True
  17. break
  18. return flag
  19. def ExtremeFloor(clickStatus,direction):
  20. exFloor = 0
  21. if(direction == 1):
  22. # check the last 1 in the clickStatus
  23. for i in range(0,len(clickStatus)):
  24. if(clickStatus[i] == 1):
  25. exFloor = i
  26.  
  27. else:
  28. for i in range(0,len(clickStatus)):
  29. if(clickStatus[i] == -1):
  30. exFloor = i
  31. return exFloor
  32. def genItList(liftAt,exFloor):
  33. if(liftAt<exFloor):
  34. return range(liftAt,exFloor+1)
  35. else:
  36. return range(highFloor,exFloor-1,-1)
  37.  
  38. # setup all the required functions
  39. # setup lift calls
  40. clickStatus[2] = up
  41. clickStatus[3] = down
  42. clickStatus[5] = up
  43. clickStatus[4] = down
  44. clickStatus[7] = up
  45. while(not stop):
  46.  
  47. if(not (hasElement(clickStatus,1) or hasElement(clickStatus,-1))):
  48. stop = True
  49. break
  50. if(liftStatus == up):
  51. #do this
  52. # find the highest floor that lift has to go.. and stop at every floor in which the person needs to go up
  53. highFloor = ExtremeFloor(clickStatus,up)
  54. for i in genItList(liftAt,highFloor):
  55. #append to the stopSequence
  56. if(clickStatus[i] == up):
  57. clickStatus[i] = 0
  58. stopSequence.append(i)
  59. liftAt = highFloor
  60. liftStatus = down
  61.  
  62. if(liftStatus == down):
  63. #do this
  64. # find the lowest floor that lift has to go.. and stop at every floor in which the person need to go down
  65. lowestFloor = ExtremeFloor(clickStatus,down)
  66. for i in genItList(liftAt,lowestFloor):
  67. #need to change stops to true in stop list
  68. if(clickStatus[i] == down):
  69. clickStatus[i] = 0
  70. stopSequence.append(i)
  71. liftStatus = up
  72.  
  73. print(stopSequence)
Add Comment
Please, Sign In to add comment