5 kyu

Vending Machines

474 of 522xcthulhu
Description
Loading description...
Puzzles
Algorithms
  • Please sign in or sign up to leave a comment.
  • andrewsleake85 Avatar

    This is not a spoiler, as the sample case is extremely easy to find and has no bearing on test cases.

    I'm having a MAJOR issue - Even the sample case, which is index 41, will not work. Example:

    vms[41].vend(); //vend only machine 41 let weight = vms.weigh(); // grab the weight console.log(weight); // returns 101, indicating that vms[41] is the special machine return 41; //return 41

    ERROR:

    Guessed incorrectly at some point

    Seriously, how am I supposed to get my code working if the sample case doesn't even work ? It doesn't matter what I return, 0-99, vms[0]-vms[99]. Every return results in " Guessed incorrectly at some point "

  • Rambutan Avatar

    I guess i ask whether this kata is implicitly asking for a binary search algorithm ( which is a key technique ) or not?

    It seems to me that it is, and learning key programming techniques is what codewars is about

    The top voted answer (in js) is very terse, but immensely inefficient. It minimises the number of weighings, but since that is limited to 10 it hardly matters.

    the top voted answer requires about 5000 operations to search a list of 100

    to find the answer using the binary search takes 100 + the weighings

    if the list was a million units long, then the top voted answer would be hopeless, but the binary search would still solve it in a flash.

    therefore i wish to downvote it as either best practice or clever, as it has optimised the wrong function in my opinion (weighings and LOC instead of efficiency and algorithm design)

  • sordidfellow Avatar

    All javascript submissions are timing out :(

    Submitting issue comment via:

    This error is not kata related. Instead, it is caused by some hiccup in the Codewars system, don't worry. It's usually fixed after a while. For more information, see this page on the github wiki.

  • superbob Avatar

    This comment has been hidden.

  • Prome Avatar

    This comment has been hidden.

  • Aut Avatar

    I felt this was a good Kata. I was stuck on it for a while until I realized something that was true about my approach. One quick hack of a method was thrown in and suddenly I had the right answer. Very nice.

  • mkumpan Avatar

    Totally unclear, does the pile get reset after each vms.weigh()? If it does, my solution should work - tested on a mockup and run through with a debugger several times over, yet it does not... If not, I'll need to re-think my solution. Also, is there any way to use the codewars test engine? I need a VendingMachines object for that, not sure how to create one, if at all possible.

  • EricFreeman Avatar

    This comment has been hidden.

  • jacobb Avatar

    You've puzzled me with other kata, always fun though. Small thing - machines as a variable name would be more readable than vms (or anything better you come up with). I say this primarily because I work at a university where people overuse abbreviations. If an abbreviation isn't relevant to who your audience is, give them something they'll understand without additional instruction. Adds to the simplicity in the sense that you don't have to say call vending machines vms, which makes me think virtual machines or a misspelling of pms.

  • akume Avatar

    vms is an object. "i" is a key in the object. you can access the key via vms[i].vend() but you can't use a "foreach" on it because it's not an array. you'd have to use a different looping algorithm

  • user8062788 Avatar

    This comment has been hidden.

  • akume Avatar

    This comment has been hidden.

  • JulianNicholls Avatar

    This comment has been hidden.

  • !untrue Avatar

    This comment has been hidden.

  • JulianNicholls Avatar

    All I'm getting at the moment is "Object # has no method 'error'". I'm not sure if it's related to the Kata or Codewars itself.

  • nklein Avatar

    I don't know if there is some edge condition with my choice of algorithm or your choice of test, but I wrote up my algorithm and failed the 'Test' three times in a row. I added a console.log() and passed 'Test' and failed 'Attempt'. I hit 'Test' again and passed it four times in a row. Then, I hit 'Attempt' and failed. Then, I hit 'Attempt' and succeeded and 'Submit' and succeeded.

  • BattleRattle Avatar

    This comment has been hidden.

  • delfuego Avatar

    This comment has been hidden.