5 kyu
Vending Machines
474 of 522xcthulhu
Loading description...
Puzzles
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
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 "
Not a kata issue, have you seen the sample tests? There is a loop there, change it to this:
And it'll work.
" The function must return the index of the machine " I dont understand how to make my question clearer. It asked to return the index of the machine. I returned 41, the index of the machine. It still does not work. I dont need a solution - I need to understand why returning the index of the machine - what the question asks me to do - is not working. If you can kindly explain to me why returning exactly what the question is asking does not work, then by all means. In my working recursive solution, I also return a single integer - the index of the special machine - which also does not work. Why is the question asking me to return " the index of the machine" of that is not working ?
The sample tests are editable, and always were, did you even try what I said? If you don't change (because you can't, seriously, dunno why you can't do it) the sample tests, eventually some guess will be wrong (it'll be too easy if the answer is always 41). What I did, was to write my code in repl.it and work with an array instead of an object, once I solved it there, I pasted my code here, adapted it to use an object and it worked.
Yes but it only works for the sample case. I still cannot return an integer for the tests. Why will the tests not allow for an intger return - the problem specifically asks " The function must return the index of the machine ". An index is an integer. An integer gives the same error, no matter what test or sample I do.
Find me in gitter and I'll see what I can do to help you.
I sent you a private message with my code. Thanks !
This issue has been resolved thanks to Chrono79. The sample case expects 100 integers, not 1. That is why the sample case will not pass even though the index is correct. Thanks Chrono79 !
Your function should return only one integer, but it's tested 100 times with different expected answers.
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)
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.
Closing since this hasnt been mentioned anymore
This comment has been hidden.
This comment has been hidden.
Your
vnw
function seems to be missing areturn
statement on the last line.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.
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.
pile does not get reset. adds 100 each time except for the one machine that adds 101. However, I cannot get the damn thing to accept my correct solution.
This comment has been hidden.
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.
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
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
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.
Code?
When you simply run the initial code you'll get this error.
Okay, I was using
console.error
under the misaken assumption that codewars implemented that. Fixed.Thanks.
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.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Okay, I no longer use
Math
at all, although I'm sure there's still hacks like this to worry about.random() can be overloaded as in my answer. You should use some test cases where the number is fixed, and some tests case where the number is random(and don't put it into a function).
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.