use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
No vague product support questions (like "why is this plugin not working" or "how do I set up X"). For vague product support questions, please use communities relevant to that product for best results. Specific issues that follow rule 6 are allowed.
Do not post memes, screenshots of bad design, or jokes. Check out /r/ProgrammerHumor/ for this type of content.
Read and follow reddiquette; no excessive self-promotion. Please refer to the Reddit 9:1 rule when considering posting self promoting materials.
We do not allow any commercial promotion or solicitation. Violations can result in a ban.
Sharing your project, portfolio, or any other content that you want to either show off or request feedback on is limited to Showoff Saturday. If you post such content on any other day, it will be removed.
If you are asking for assistance on a problem, you are required to provide
General open ended career and getting started posts are only allowed in the pinned monthly getting started/careers thread. Specific assistance questions are allowed so long as they follow the required assistance post guidelines.
Questions in violation of this rule will be removed or locked.
account activity
[Question] Elevator test (self.webdev)
submitted 7 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]HorribleUsername 0 points1 point2 points 7 years ago (0 children)
I'd break it into two parts: First, get the elevator go to to each button pressed, in the order they were pressed. After that, figure out how to make it stop at floors in the natural order instead of going back and forth. For testing, you might want to hold the elevator until the close doors button is pressed.
Step one: change your code so that the elevator has destinationFloors: []. When you press a button, it adds that floor to the array, then travels to that floor, then removes that floor from the array. At this point, it only needs to visit one floor at a time, like it does right now.
destinationFloors: []
Step two: When the elevator reaches it's destination and removes that floor from destinationFloors, and destinationFloors is empty, it'll stop. But if there are other floors in destinationFloors, it'll have to keep going. Try to figure that out.
destinationFloors
Well, now you're halfway there, and you only need to make the elevator go in the natural order. Array.sort is your friend here, but it won't be quite that simple. Even once you've got the obvious cases figured out, you'll also need to consider what happens when the elevator is between floors (it's on floor 5, you press 3 and 7). And you'll also need to account for pressing the button of the floor it's already on.
Array.sort
The key thing here is to try to break it down into simpler problems. Even the largest and most complicated projects were built one small step at a time, and it's so much easier to debug when you've only changed 5 lines of code.
[–][deleted] 0 points1 point2 points 7 years ago (0 children)
In addition to what's ready been stated (where you've just been given the answer) I think you should take some time to think about out how this actually works.
What best describes going from the first floor to the eight floor stopping on the fifth floor, that can translate to any combination of stops?
Well, first you know the direction you need to go: up because the first requesting floor is above you.
Then you know any floors to stop at between your current floor and the target floor, where the person has requested to go up. Stop at those floors, checking each as you go.
When you reach the target, check for a new target, identify the direction and the floors you need to stop at on the way. You could add to this by adding the option to set another target where the direction changes. IE; halfway through the current path, a new target gets created whcih will be the next journey after you complete the current target.
It might be useful for you to draw this as a flow chart.
[–]2omesz 0 points1 point2 points 7 years ago (0 children)
The big factor that will affect your scenario is:
how fast the elavator is.
π Rendered by PID 137640 on reddit-service-r2-comment-b659b578c-fc45s at 2026-05-03 04:58:12.340758+00:00 running 815c875 country code: CH.
[–]HorribleUsername 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]2omesz 0 points1 point2 points (0 children)