3 kyu

The Lift

575 of 3,451dinglemouse
Description
Loading description...
Algorithms
Queues
Data Structures
  • Please sign in or sign up to leave a comment.
  • pwiniarski Avatar

    This comment has been hidden.

  • Just4FunCoder Avatar

    TypeScript fork

    • Fixes random test generation by using let instead of var caused to async bug (Fixing issues [1] [2] [3] [4] )
  • 1alexvash Avatar

    Me: this kata looks too easy for 3kyu

    Me 7 days later of non stoping coding: hold on, I almost solved it

  • 1alexvash Avatar

    I was submitting my code 10 times, and finally it passed random tests, lol

  • AlexRz912 Avatar

    This comment has been hidden.

  • brodiemark Avatar

    Very nice problem - thanks!

    One question: Why do Python solutions need to deal with the mysterious Dinglemouse object? Why not just define a function with parameters queues and capacity, as in the other languages? That's how I wrote the code in my IDE, only to discover that I needed to insert self. everywhere to make it work.

  • Astol Avatar

    Finally after days of trying managed to get it! I really liked the idea of this kata and it was really fun solving it. Only thing I would point out is maybe the rules aren't that clear. Wasted a few days just because I misinterpreted some of the rules and their priorities. Other than that it was great!

  • Roiqk7 Avatar

    This comment has been hidden.

  • 84NewSk Avatar

    Javascript

    why this var queues = [[], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], ] with capacity of 5 should equal to [ +0, 6, 5, 4, 3, 2, 1, +0, 5, 4, 3, 2, 1, +0, 4, 3, 2, 1, +0, 3, 2, 1, +0, 1, +0 ] ? first lift goes to 6th floor, takes 4 guys, then to the 5th, takes 1 guy, and after goes direclty to 0, no? why stopping at 4 ?

  • jphamilton Avatar

    Dinglemouse, really enjoyed this one, but seemed a little too easy for 3kyu. Found a pretty straightforward solution in about an hour where I've spent a week on some of your others.

  • VanGex Avatar

    cool kata, I enjoy it.

  • lfsegoro Avatar

    Passed basic and several random test. Remaining several random test failed. I think I have the clue "prioritize the caller on other floor if its same direction with previous direction", "queue of the current floor not always granted to enter although the lift is empty" But still confuse how to implement this clue. Using python, took many hours with my level of coding but still not solved :)

  • DE0000 Avatar

    Amazing kata, enjoying it so far. Sadly, reloaded the page without saving and lost some progress. Don't forget to save your work, people! :)

  • b-valiyev Avatar

    Love it. Really enjoyed this kata. Thanks for your effort!

  • Sarmouts Avatar

    can someone explain me what does this mean : "When called, the Lift will stop at a floor even if it is full, although unless somebody gets off nobody else can get on!" I dont get it

  • thedaveCA Avatar

    headdesk

    *Every* *single* example I try works fine, but some random test gets me, or maybe a "tricky" one. But that's the key, maybe.

    Pro tip: Reset your variables on each pass. I wrote this as a class first, noticed it was expecting static, shrugged and threw static in front of everything. Who cares, nobody is going to create multiple objects anyway since the kata only calls a static method.

    Well, turns out I care since I'm using the static constructor.

    // C# is an object oriented language, so let us orient this as an object.
    public static int[] TheLift(int[][] queues, int capacity)
        { 
            Dinglemouse dinglemouse = new();
            return (dinglemouse.TheLiftX(queues,capacity));
        }
    

    Roll back to my first Git commit, toss ^^^ in, and it passes!

    Still my fault, clearing variables is Programming for n00bs 101, but I guess I'm finally thinking in objects now...

    I did decide to leave in some of the extra edgecase handling that I wrote while trying to figure out where I was going wrong, I'll leave you with this one:

    // This person wants to stay on their current floor.
    throw new Exception("This person is too dumb to survive, let's push them into the elevator shaft now and be done with it.");
    

    Although the Kata doesn't require it, I highly recommend it.

  • lutre69 Avatar

    Don't know if it's the heat of the summer or what but this kata got me stuck for a little while. I won't look at elevators the same way indeed ;-)

  • Krillan Avatar

    Ruby

    All Fixed Tests have the same input:

    [[], [], [], [], [], [], []], 5

    so they all pass anyway.

  • ZachRobs Avatar

    This comment has been hidden.

  • remote12 Avatar

    A very well thought kata indeed. Appreciate it very much . I got to the solution ,but the real problem for me was "Server Timeout" on submition.

  • jurijk97 Avatar

    very fun kata, nice challenge

  • Kostyleva Avatar

    I write on Python. Tests passed. I attempt and the first 4 tests passed but test "Up and down" Execution Timed Out (12000 ms) I tried to optimiszed my code. But the error have occures yet.

    What should I do?

  • immmdreza Avatar

    [Rust]

    Second test case has a person wanting to go the the floor he's already in.

    &[vec![], vec![], vec![1, 2], vec![], vec![], vec![], vec![]]
                      ----------
                       2nd floor
    
  • ahagert Avatar

    Hi, I have a problem with the highlander test, perhaps I messed something up? It is [ [], [2], [3,3,3], [1], [], [], [] ] (capacity = 1). My lift goes

    1. to level 1 and takes the 2 (=>[0,1])
    2. to level 2, releases the 2 and takes the first 3 (=>[0,1,2])
    3. to level 3, releases the 3 and takes the 1 (=>[0,1,2,3])
    4. to level 2, do a stop because of the full-capacity-rule (=>[0,1,2,3,2]), ...

    Problem1: Test tells me, I'm wrong on index 4 (expected 1 instead of 2) ??? Problem2: If I don't stop at 4. the test gets passed but then I miss the FireDrill-Test :-(

    Could someone tell me where I'm wrong? Thanks a lot!

  • rodonoah Avatar

    interesting kata! every elevator trip will look different now

  • Omppu Avatar

    Great problem!

  • j12345678910 Avatar

    [Typescript] I'm having the same issue as @metawort. Basic & other tests pass. First random test R#0 passes. All other random tests fail;

    • all have same queues and capacity (despite different test descriptions)
    • all expect result [+0]
  • KiplandDynamite Avatar

    This comment has been hidden.

  • realitant Avatar

    My only complaint is with one slightly unclear part of the instructions. Suppose I have the following setup: G:[1], 1:[0], 2:[0] After the passenger from the ground floor disembarks on floor 1, the lift is empty. I felt it was unclear whether or not the passenger going down from floor 1 was allowed to enter (they are not). Other than that, this kata was a joy to work on.

  • QuadratClown Avatar

    There is a possible issue with the TypeScript tests; In my solution, everything works fine - except the FIRST random test R#0. It fails every time, no matter of the input values, while all other random tests succeed. This behaviour is always consistent.

  • jorgeLannister Avatar

    One thing is not clear : If elevator is going up, left the last passenger and became empty he has to check if there is anybody going up on the floors above, before checking who is the person coming down from the highest floor.

    But, it's not clear what happens if there is a second passenger going up. For example :

    • Elevator just went up, stopped at floor 2 and left last passenger and queue looks like this :
    • (), (), (), (0, 5), (), (0)
    • Should it pick up the second passenger on floor 3 and keep going up, or should it go to the 5th floor and pick the passenger going down to 0 ?

    Thank you

  • adkuca Avatar

    This comment has been hidden.

  • shevalye Avatar

    final int[][] queues2 = { new int[0], // 0 new int[0], // 1 new int[]{4,4,4,4}, // 2 new int[0], // 3 new int[]{2,2,2,2}, // 4 new int[0], // 5 new int[]{0,2,4,4,2,2,4,4,2,0}, array lengths differed, expected.length=7 actual.length=10; arrays first differed at element [3]; expected:<2> but was:<4> capacity is 2; why 2 expected. lift goes up picks up people on floor 2 than they go off on floor 4 then continue go up to flooor 6 and then goes down but stops at floor 4 again cause there are people waiting to go down even if lift is fuull

  • shevalye Avatar

    final int[][] queues2 = { new int[0], // 0 new int[0], // 1 new int[]{4,4,4,4}, // 2 new int[0], // 3 new int[]{2,2,2,2}, // 4 new int[0], // 5 new int[]{0,2,4,4,2,2,4,4,2,0}, capacity 2 array lengths differed, expected.length=7 actual.length=10; arrays first differed at element [3]; expected:<2> but was:<4> why it expected 2 when lift should go up till the end and on the way down stop if someone waiting to go down even if it is full so it should stop at 4. it goes first to 2 picks up then to 4 then to 6 and then has stop at 4 cause there are people there waiting to go to floor 2?

  • v1taly Avatar

    When called, the Lift will stop at a floor even if it is full

    Rather confusing rule. More logically do not stop when it full, otherwise our lift not so "smart".

  • akar-0 Avatar
  • akar-0 Avatar
  • Ninfea Avatar

    It's my first time writing here on codewars. I liked this kata, the idea is very creative, so congratulation to dinglemouse for his or her brainchild! Sadly, for me was very hard to understand how this lift works, because of my so-so English. I misanderstood some instructions at first and I could pass 11 out of 15 tests, therefore I had to changed a lot of things in my code. Eventually, I was able to pass this kata, but I think that I could do better, because something in my code could have written better without repetitions, but I have a headache at the moment, so I leave it as it is.

    Bye :)

  • sorokaIlya Avatar

    Someone can explain for me what's wrong with the fire drill test. I really straggle on that (

  • Timothyhoytbsme Avatar

    This was fun. Took me a few hours because I changed a few things and was confused for a bit.

    To clear up the instrucitons, I would reword them:

    -The lift stops if someone needs off or someone needs on (going in same direction) -The lift only turns around if empty and no one reamining on floors in current direction -The next stop is always either the next floor someone needs off, the next floor with someone needing on going the same direction, or the last floor with a person going the opposite direction.

  • PashaM999 Avatar

    I just don't get the logic behind some of the tests. For instance in 'Yoyo' case we get:

    [(), (), (4, 4, 4, 4), (), (2, 2, 2, 2), (), ()] with capacity 2

    It is clear to me that we should first pick up people on floor 4, because at the beginning the lift is empty, and is obviously going up, because there is not other way to go from the ground floor. Now, from the task we are told that: "When empty the Lift tries to be smart. For example, If it was going up then it may continue up to collect the highest floor person wanting to go down"

    Clearly, people on floor 2 want to go up, and floor 2 contains highest floor people wanting to go down, yet the answer suggests the following path:

    [0, 2, 4, 2, 4, 2, 0]

    My solution would be:

    [0, 4, 2, 4, 2, 4, 0]

    The same goes for the test: [(), (0, 0, 0, 6), (), (), (), (6, 6, 0, 0, 0, 6), ()] with capacity 5. Why should we stop at 1 if there are people who want to get from 5 to 0?

    I cannot understand the logic behind this, and, therefore, cannot solve this kata. Can anyone explain?

  • egilgamesh Avatar

    How come the last test showed the lift stops on the 1st floor?! there is neither queue nor a request to go for the first floor in the queue list?

       int[][] queues =
        {
            new int[0], // G
            new int[]{0}, // 1
            new int[0], // 2
            new int[0], // 3
            new int[]{2}, // 4
            new int[]{3}, // 5
            new int[0], // 6
        };
        var result = Dinglemouse.TheLift(queues, 5);
        Assert.AreEqual(new[] { 0, 5, 4, 3, 2, 1, 0 }, result);
    
  • EsaieB Avatar

    [Python]

    On basic test "Highlander" in python, the test is : Queues : ((), (2,), (3, 3, 3), (1,), (), (), ()) Capacity : 1

    And I've the following result : [0, 1, 2, 3, 2, 1, 2, 3, 2, 3, 0] should equal [0, 1, 2, 3, 1, 2, 3, 2, 3, 0]

    But according to lift rule "When called, the Lift will stop at a floor even if it is full, although unless somebody gets off nobody else can get on!"

    the elevator should stop at the second floor after having picked the people at the 3rd floor.

  • zappa78 Avatar

    yeah, that was fun.

    What I found confusing in the description was

    If it was going up then it may continue up ...

    I'd rather phrase that like:

    If it was going up then it will continue up ...

  • akar-0 Avatar
  • nichtl Avatar

    fun kata ,this kata took me about four days ,i really enjoy it

  • Nam01ar Avatar

    my code is a mess...but i dont understand why i pass all regular tests i attempt and i get mistakes because result is None...as it is not returning anything...if that is the case and the code is not returning the result...how is possible that regular tests are ok?

  • janedoe. Avatar

    Fun kata, the task is simpler than you think

  • fibonaccios Avatar

    Funny little kata - was expecting some kind of animal though ;) Evening definitely well spent!

  • NilsHoffmann Avatar

    First of all thank you for this wonderful kata! It's very realistic and of so much use for other problems.

    The instructions are amazing. But there is one thing I don't really like: The hint the lift tries to be smart part. It may continue in the same direction. (I think this is misleading and make things more complicated than neccessary) It actually continues in the same direction until it isn't possible anymore. The lift just doesn't stop, unless it has to (somebody wants to leave or enter the lift).

    Example: lift is moving upwards and is in floor 6 of 7, the lift is empty. It always moves to floor 7 (even if there isn't anybody) and then turns around and moves downwards it just doesn't stop until it reaches a floor in which someone is waiting for the elevator moving downwards.

  • arison Avatar

    So i have quick question.

    I am getting time out error and if someone could tell me if this kata is getting computation heavy later or am i just having infinity loop somewhere, just wanna figure out what's wrong before i start changing stuff

  • wayne1512 Avatar

    This comment has been hidden.

  • damage99 Avatar

    [C++]

    maybe someone can explain why this test is considered correct?

    capacity: 5; input ppls: [] [0 0 0 0 ] [0 0 0 0 ] [0 0 0 0 ] [0 0 0 0 ] [0 0 0 0 ] [0 0 0 0 ];

    Expected: equal to [ 0, 6, 5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 4, 3, 2, 1, 0, 3, 2, 1, 0, 1, 0 ] - i think it's wrong

  • FArekkusu Avatar

    C++ fork removing warnings generated by tests.

    It should be checked that the default language version doesn't revert to C++ 14 because this happens inside the kumite editor for some reason.

  • metawort Avatar

    After the random TypeScript test cases have been updated, the function is only called once per test case (as should be). They still fail though, because the expected result is always [ 0 ]...

    Still the first test passes (apparently with a different expected result) and the following test cases use the identical input values as the first one. Test case titles are still BS as well.

    Example:

    R#0: 10 floors, 23 people, lift holds 2

    theLift([ [ 2, 3, 1, 2 ], [ 0, 0, 2 ], [], [ 2 ] ], 3, [], 1) -> [ 0, 1, 2, 3, 2, 1, 0, 2, 0 ] passes

    R#1: 7 floors, 19 people, lift holds 5 (and following)

    theLift([ [ 2, 3, 1, 2 ], [ 0, 0, 2 ], [], [ 2 ] ], 3, [], 1) -> [ 0, 1, 2, 3, 2, 1, 0, 2, 0 ] fails with expected [ 0, 1, 2, 3, 2, 1, 0, 2, 0 ] to have the same members as [ 0 ]

  • pacman09 Avatar

    COMMENT UPDATED AND CHANGED FROM QUESTION TO ISSUE (original comment is below, found issue described in reply)

    Coding in TypeScript - I am still getting first random test failed (all the other test are always passed, just first random test R#0 is failed) and no idea why, because sometimes it is really simple test case. Here is the example with logs:

    R#0: 18 floors, 45 people, lift holds 5
    Log
    input parameter result: [ 0, 1 ]
    queues: 
    [ [], [], [ 1 ], [] ]
    capacity: 4
    return: [0, 2, 1, 0]
    input parameter result: undefined
    queues: 
    [ [ 1 ], [], [ 1 ], [] ]
    capacity: 4
    return: [ 0, 1, 2, 1, 0 ]
    expected [ 0, 1, 2, 1, 0 ] to have the same members as [ 0, 2, 1, 0 ]
    

    It looks that there are actually 2 tests, and result from the first is the expected one ([0,2,1,0]), also second result is correct based on the input queues, but the second result is compared with expected result from first test and it is obviously failed.

    Another thing, I don't understand why there are required input parameters result and direction, as you can see in example above, in first test the input parameter result has assigned value [ 0, 1 ] and in second test it is undefined. Maybe this causes the issue, because the second result always contains this result parameter from first test at the beginning. Another example just to see it clearly:

    R#0: 6 floors, 6 people, lift holds 3
    Log
    input parameter result: [ 0, 1, 2, 3, 4 ]
    queues: 
    [ [], [], [ 4, 0, 3 ], [], [] ]
    capacity: 4
    return: [ 0, 2, 3, 4, 2, 0 ]
    input parameter result: undefined
    queues: 
    [ [ 1, 4, 4, 1 ], [ 3, 2 ], [ 3, 4, 0, 3 ], [], [] ]
    capacity: 4
    return: [ 0, 1, 2, 3, 4, 2, 0, 2, 3, 4, 0 ]
    expected [ 0, 1, 2, 3, 4, 2, 0, 2, 3, 4, 0 ] to have the same members as [ 0, 2, 3, 4, 2, 0 ]
    

    You can see that result from first test is expected result, and result from second test starts with the input parameter result from first test ([ 0, 1, 2, 3, 4 ]).

    It is really wierd that all the other complex tests are always passed, only this one fails. Am I missing something here or is this an issue of the test?

  • Seawolf159 Avatar

    5 or 6 hours across three days and i get Passed: 23 Failed: 11. Fire drill is killing me now and the random tests. Can't figure out what the queue must be for the fire drill and what the capacity is to give that result to test it. Is this too long to spend on this?

  • Kees de Vreugd Avatar

    When I started solving this thing, I thought: "Hm... is this really a 3 kyu?" Two days later I thought the same thing, but for the opposite reason. Almost went crazy trying to untangle a mess of if - then - else if - else statements. It took me two long walks with dogs to figure out how to do this, with a completely different approach to the problem.

    I love this one!

  • dawidszewczyk Avatar

    [], [0, 0, 0, 6], [], [], [], [6, 6, 0, 0, 0, 6], []

    I need your help:) Looking at the instructions on this "testTrickyQueues" input I understand (and this is what my code does) is that:

    From the bottom, the first "passenger" in queue seeks to go down - thus the Direction of the Lift is set to DOWN. Since there is someone on the 5th floor (3 "passengers" actually) who also seek to go down, lift should me smart enough to regonize this and: firstly go to floor 5, pick 3 "passengers" than on the way down on the floor 1 collect 2 additonal "passengers" and let 5 pepole out on the ground floor.

    So now the queues on each floor look like this: [], [0, 6], [], [], [], [6, 6, 6], []

    With this logic, the output is at this stage is: [0, 5, 1, 0] and there are still "passengers" awaiting.

    I'm failing 2 from 16 tests, one of them is "testTrickyQueues" and it says that: arrays first differed at element [1]; expected:<1> but was:<5>

    Meaning that we should ignore the fact that on the 5th floor three pepole are willing to go down and pick up the passengers from floor 1. Which doesn't make sense considering the instructions but I MIGHT simply misread them

  • NykSu Avatar

    Good task! It is very important to read carefully here. The first time was not attentive. The elevator stops for all calls, even if there is no room and no one gets out - it turns out this is important!

  • NykSu Avatar

    Wrong tests.

    It is map of floors: [[], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] Capacity is 5 My lift is: [0, 6, 5, 0, 5, 4, 0, 4, 3, 0, 3, 2, 0, 1, 0] Test lift is: [0, 6, 5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 4, 3, 2, 1, 0, 3, 2, 1, 0, 1, 0]

    Test is ubnormal.

  • Dasffafa Avatar

    I was extremely astonished when I realized "'tuple' object has no attribute 'pop'" and I had to push down all my solutions and do again :(

  • cl_tch Avatar

    One of the best Kata I've solved (or even looked at) on this website. Struggled a bit in the beginning (mainly because I was misunderstanding the question), but I completed it with a semi-decent solution. Really cool question, thanks!

  • SBHSOdin Avatar

    One of the most enjoyable questions I've solved on Codewars. Nice question.

  • ThePoisoned1 Avatar

    Really enjoyed this kata. Very interesting and fun to code

  • fpineda3105 Avatar

    Great Kata!! thanks.

  • alexc19 Avatar

    I liked this kata, thanks! I'm fairly happy with my solution but I guess it could be a bit more efficient removing some unnecessary comparisons when selecting the next floor.

    What I did not like is the solution stub: why do I have to start from class Dinglemouse(object)? In hindsight since I did not need objects I should have ignored the class stub and written my solution as an independent function.

  • seleemdz Avatar

    Very interesting kata. Thanks!

  • Danchieke Avatar

    Potential issue with Typescript tests.

    I have this test case:

    [ [ 3 ], [], [ 1, 4 ], [ 1, 4, 0, 0 ], [], [ 4 ] ]
    Capacity:  5
    

    which has this solution

    [ 0, 5, 4, 3, 2, 1, 0 ]
    

    According to the question, people can get on the ground floor at the start of the problem. So why does this lift not stop at Floor 3 before proceeding to Floor 5? And in that case, it would also stop at 2 and 4 on the way up.

  • josaffe Avatar

    This comment has been hidden.

  • JiPiBi Avatar

    Hi Please could you check if my timeout is only inefficiency or an infinite loop in the attempt tests and if inefficiency, is it linked to the use of too many methods or just messy implementation ?

    Thanks in advance

  • Micael7 Avatar

    After some tampering, my first solution that got all the test cases right, passed almost all the other cases, except some random ones and the "full up, full down" one. Was searching for almost an hour, and could not find where the algorithm was wrong. Only later did i discover that i mistakenly put an "is greater" instead of "is greater or equal" operator in a for loop with a lengthy continuation condition. Great Kata, had lots of fun :D

  • Lazyt3ch Avatar

    Hello everybody,

    I believe I've found a test that might contradict the problem statement (see below).

    highlander queue = [ [], [ 2 ], [ 3, 3, 3 ], [ 1 ], [], [], [] ] capacity = 1

    To make sure I did not make a mistake in my code, I took a pen and a piece of paper, drew a simple diagram, and followed all the lift movements. Here's what I got:

    [0, 1, 2, 3, 2, 1, 2, 3, 2, 3, 0]

    That's exactly the result produced by my code that I'm trying to debug.

    But, according to the test, the following result is expected:

    [0, 1, 2, 3, 1, 2, 3, 2, 3, 0]

    That is, the lift presumably must not stop on floor #2 after leaving floor #3 for the first time.

    But here's what the problem statement specifically says:

    "When called, the Lift will stop at a floor even if it is full, although unless somebody gets off nobody else can get on!"

    Any comments are welcome. Of course, I might have misunderstood something. Actually the kata is great, and I've been happily debugging my clumsy solution. :)

    Cheers.

  • steve_zhu Avatar

    That fire drill test is wrong. In the event of a fire, everyone is suppose to use the stairs.

  • Shiv  Singh Avatar

    Fun Kata! Loved it

  • user7531853 Avatar

    Hi, I have added a TypeScript translation!

    Will someone please review it?

    Thanks.

  • user7531853 Avatar

    Cool kata!

    Wonder why so few people are using a recursive function for this, seems like the obvious solution.

  • MobulaKuhlii Avatar
  • tortar Avatar

    Beautiful kata, but too high rating : my solution is a total mess but I managed to pass all tests :D (I feel bad to go away with a so poor solution, I will update it)

  • Blueluelueluelue Avatar

    Will the lift stop at a floor where all the people on that floor want to go in the opposite direction from the lift's current direction? For example, the lift has a passenger 6 and is heading up from floor 1, there is a person on floor 4 who wants to go to floor 0. I know the person on floor 4 can't get on the lift since the lift's current direction is up but he wants to go down, but will the lift stop at floor 4 or will it just continue going up to floor 6?

  • OldGitCoder Avatar

    Really excellent and challenging kata!

    I am, however, stuck on what seems to me to be a conflict between 2 of the lift rules:

    The Lift never changes direction until there are no more people wanting to get on/off in the direction it is already travelling
    
    When empty the Lift tries to be smart. For example,
       If it was going up then it may continue up to collect the highest floor person wanting to go down
       If it was going down then it may continue down to collect the lowest floor person wanting to go up
    

    For example: lift is going up and discharges all passenger at floor 3. There are 2 people waiting at higher floors say, 1 at floor 6 wanting to go to floor 10 and 1 at floor 9 wanting to go to floor 5.

    Does it

    a) follow the empty lift rule and go straight to floor 9, then to floor 5 and then to 6 for passenger going to floor 10? 
    

    or

    b) continue up, stop at 6 for 1 passenger, take him to floor 10 then come back to floor 9 to take final passenger to floor 5?
    

    Option b) seems the more logical but appears to conflict with the empty lift rule. I'm probably just being dense, but would really appreciate some clarification.

  • Alex2310 Avatar

    Excellent kata!

  • Fchilling Avatar

    Thanks for this nice kata. But in C++ I am struggling with the 'Highlander' test. All the other tests are passing fine.

    So with a capacity of '1' the queue is queues = { {}, {2}, {3,3,3}, {1}, {}, {}, {} };

    Expected: equal to [ 0, 1, 2, 3, 1, 2, 3, 2, 3, 0 ] Actual: [ 0, 1, 2, 3, 2, 1, 2, 3, 2, 3, 0 ]

    The rule is to stop on the way up/down when somebody is waiting, even when the max capacity is reached. So why is it expected to jump from floor 3 to 1, without stopping for the two people still waiting at floor 2 to go to floor 3?

    Is there a bug or do i misread the rules? Thanks for a short answer!

  • SolManX Avatar

    I have to add my praise for this interesting and enjoyable kata!

    It was really good to see other -- more concise and clever -- solutions as well. Very instructional.

    Thanks.

  • KubajsDMZ Avatar

    This comment has been hidden.

  • pathbart Avatar

    This comment has been hidden.

  • maxchiodo Avatar

    The elevator problem was one of my first school projects in CS. Seems easy at first but it's non-trivial. Good kata. After a few attempts I managed to come up with a simple solution. It's like a piston. Up and down, up and down. But where do you stop, that's the question.

  • vinsenvl Avatar

    The people in my work building sometimes go into the lift even when the lift is moving in a different direction than their destination is. Because they actually expect the lift will be full when it comes back to that floor. xD

  • ExtraAlien Avatar

    JS, the situation is: The solution have passed all the tests, but when i pressed submit, 1 of random test failed. i have repeated several times and found out : sometimes random tests pass, sometimes got 1-2 fails of ~30 tests. suppose there is some mistake in my approach, for now got no idea what is the mistake, maybe there is some specific conditions that random tests can not cover. All 'fixed' tests got pass anyway

    Very funny kata,btw

  • geoffp Avatar

    Nice one. Worked on it for 3 hours, then threw all my code away and started again. Eventually it dawned on me that a simple solution is possible, if you take the time to think of it.

  • widelec9 Avatar

    I don't understand this test case: queue = [[8, 8, 6], [8, 3, 4, 7], [], [2, 6, 8, 5], [], [0, 8, 8, 4, 1], [], [3, 2, 2, 3], []] capacity = 9 result should be: [0, 1, 3, 5, 8, 7, 5, 3, 2, 0, 1, 3, 5, 6, 8, 7, 5, 3, 2, 1, 3, 4, 5, 6, 8, 5, 4, 0, 1, 3, 5, 7, 8, 5, 1, 3, 5, 8, 0]

    Why does element #3 (0-indexed) in the result equal 5? After stopping at floor 3, people in the lift are: [8, 8, 6, 8, 4, 7, 6, 8, 5] (because 3 exited here), so I assume we should stop at floor 4 next, not 5. What's going on here?

  • udovr Avatar

    This comment has been hidden.

  • KataSideKick Avatar

    C# Translation added.Please review and approve~

  • WatsonMC Avatar

    This was a very good one, and made me realise some weaknesses in my planning of more complex tasks. Definitely need to refactor my mess..

    There was also a fair bit of confusion from the queuing rules which I was mired in. Could I suggest: "Only people going the same direction as the Lift may enter it, and they do so according to their "queue" order" changed to -> "Only people going the same direction as the Lift may enter it" + "People enter accoriding to their "queue" order, but those not able to enter do not block those behind them that can enter" or "People enter accoriding to their "queue" order, but those those not able to board will move aside for those behind them that can"

    Something to make it clearer that the single floor queue is effectively two queues: the upQueue and the downQueue.

    Very satifsying overall, thank you.

  • Kaboms Avatar

    I can not undestand. Why the fire_drill test 6 {0,0,0,0} 5 {0,0,0,0} 4 {0,0,0,0} 3 {0,0,0,0} 2 {0,0,0,0} 1 {0,0,0,0} 0 {} has the result: [0, 6, 5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 4, 3, 2, 1, 0, 3, 2, 1, 0, 1, 0] with capacity 5. Why does the lift stop at 4, 3, 2, 1 floors after he took four people on the fifth floor and another one on the fourth? Shouldn't he then go down to the ground floor to drop them off? I use С++

  • AlphaCentauri4.4 Avatar

    Ha! Otis is getting it's firmeware fixed on codewars. For free! :-D

  • paulc Avatar

    This is a great kata! The tests were very well written. Thank you!

  • FArekkusu Avatar

    C++ translation. Please, review and approve.

  • intranuclear Avatar

    Did something just change? It appears something is broken in the tests. For example, for queue: ((3, 3, 3, 3, 3, 3), (), (), (), (), (4, 4, 4, 4, 4, 4), ()) , 5 It says, should equal [0, 1, 2, 3, 6, 5, 3, 2, 0]

    Another example: ((3, 3, 3, 3, 3, 3), (), (), (), (), (4, 4, 4, 4, 4, 4), ()) , 5 Says, should equal [0, 3, 5, 4, 0, 3, 5, 4, 0]

    I am using Python 3.6

    It seems I saw that reported correctly 1 day ago.

  • joshua082390 Avatar

    I'm pretty confused here. Does the order of the people matter in the queue matter or not? In the testTrickyQueues case it doesnt but I have a random case where the only expalantion as to why I am getting it wrong is that it does.

    4: [2] 3: [4, 1, 0, 4] 2: [3, 4, 4, 4] 1: [0, 4] 0: [4, 3]

    Answer says it's 0, 1, 2, 3, 4, 3, 2, 1, 0, 2, 3, 4, 0 but I'm getting 0, 1, 2, 3, 4, 3, 2, 1, 0, 2, 4, 0

    The only way that 3 can be at the end is if when the elevator stops at floor 3 in the beginning it doesn't get the 4 that's last in line, which means it picks up the first 4 and then order suddenly does matter.

    Am I missing something?

    Also, the capacity is 4 so there's no capacity issues encountered

  • zapakh Avatar

    This is reminiscent of a project I was supposed to do in school but never did. And now I have!

  • iftheshoefritz Avatar

    When I solved this 3Kyu I think I only got 2 points. I'm currently at 4Kyu, is that right? Other people at work getting like 20 points at a time from solutions higher than their level. I mean, I totally understand that the awful code I wrote might deserve only 2 points ... but I don't think that's how this works? Call it a refactoring in progress :).

  • FArekkusu Avatar

    Ruby translation. Please, review.

  • wayne1512 Avatar

    If the lift is going up and at floor 3 it finds [2,5,5], will the 2 climb in or will he stay out? Also if he doesnt climb in, can the 5s go in since the lift is going up?

  • rahulk8671 Avatar

    lift rule #6 "When called, the Lift will stop at a floor even if it is full, although unless somebody gets off nobody else can get on!"

    I'm confused with this rule, what i understood is when the lift is full it will stop at floor even though no one can get in, although they could have get in if lift wasn't full. Am I correct or wrong, please help.

  • pottafa Avatar

    This comment has been hidden.

  • alexshavlovsky Avatar

    Pure OOP task. With elements of industrial automation. And very confusing explanation of the lift logic.

  • CrimsonBlaze Avatar

    This comment has been hidden.

  • Little Noah Avatar

    What is the expected result for this test case?

    capacity: 5 floor 0: floor 1: 0 0 0 6 floor 2: floor 3: floor 4: floor 5: 6 6 0 0 0 6 floor 6:

  • Jomopipi Avatar

    really a great kata to practice organization

  • Gerrit-K Avatar

    I really liked this one, but I think the description could use a little more "redundancy". I mean it's precise (i.e. it describes the problem completely) but I had a hard time figuring out some details. Just a little explained example, e.g. for testDownAndDown or testTrickyQueues could really help. However, analyzing the test cases and figuring this out was kind of an interesting part too, so ...

  • dcsmith Avatar
    The Lift never changes direction until there are no more people wanting to get on/off in the direction it is already travelling"

    Confused myself for a while because my interpretation of this was "until there are no more people wanting to travel in the direction it is already travelling." Then I finally realized it actually means "until there are no more people wanting to get on or off of a floor that the lift is currently approaching." :P

  • jarone Avatar

    good details!

    The second kata in my collection.

  • Jomopipi Avatar

    I'm averaging 55 ms on the sample tests. How close am I?

    great kata btw

  • metalim Avatar

    Very nice Kata. The lesson I learned: even "smart" rules, when applied to tech can become trivial ones. Or vice versa: trivial tech rules look like "smart" ones, when descibed in human language. :smiling_imp:

  • metalim Avatar
  • lechevalier Avatar

    Python: Actual and expected results are swapped in random tests.

  • johncoleman83 Avatar

    This comment has been hidden.

  • Blind4Basics Avatar

    approved!!! ;)

  • hufftheweevil Avatar

    I certainly appreciate the detailed instructions thus far, but I feel there are still questions left unanswered. And trying to apply the "what would happen in real life?" rule is not easy. Let's face it, this kata isn't very representative of the real world. For one major thing, the real world has a time dimension which this kata does not address. This kata assumes that everyone pushes their respective call button at the very beginning. I'm not suggesting we need to add a time argument or anything like that. But I do want to point out that, for some cases, it's difficult to compare this to the real world.

    That being said, I eventually figured out the answers to all my questions. Perhaps that's half the challenge. But I felt like that's now how it was designed.

    Overall, it's was quite a fun kata to do. Even before doing this I've always thought about elevator logic when waiting for or in one. Maybe, now that I've 'programmed' one, I won't so much.

  • daddepledge Avatar

    Just completed this in Python. A class idea, thank you. There appears to be some sort of codewars delay as I cannot see my solution but am allowed to see other solutions.

  • Blind4Basics Avatar

    Hi,

    I'm working on the translation and I would like to ask you for one thing : in python tests, I don't have an equivalent of assertArrayEquals. For now, I used a simple assertEqual but this way, the full moves solution is displayed in the "expected" part when a test fails. This will make the kata a bit easier (but just a bit). Are you ok with that or would you rather like that I create a behaviour equivalent to assertArrayEquals ? (that would not be a problem, it's just a little more work)

    Your opinion about that, please ?

    Cheers,

    B4B

  • Blind4Basics Avatar

    This comment has been hidden.