Guest User

Untitled

a guest
Jun 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 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. #
  40. while(not stop):
  41.  
  42. if(not (hasElement(clickStatus,1) or hasElement(clickStatus,-1))):
  43. stop = True
  44. break
  45. if(liftStatus == up):
  46. #do this
  47. # find the highest floor that lift has to go.. and stop at every floor in which the person needs to go up
  48. highFloor = ExtremeFloor(clickStatus,up)
  49. for i in genItList(liftAt,highFloor):
  50. #append to the stopSequence
  51. if(clickStatus[i] == up):
  52. clickStatus[i] = 0
  53. stopSequence.append(i)
  54. liftAt = highFloor
  55. liftStatus = down
  56.  
  57. if(liftStatus == down):
  58. #do this
  59. # find the lowest floor that lift has to go.. and stop at every floor in which the person need to go down
  60. lowestFloor = ExtremeFloor(clickStatus,down)
  61. for i in genItList(liftAt,lowestFloor):
  62. #need to change stops to true in stop list
  63. if(clickStatus[i] == down):
  64. clickStatus[i] = 0
  65. stopSequence.append(i)
  66. liftStatus = up
  67.  
  68. print(stopSequence)
Add Comment
Please, Sign In to add comment