6 kyu
Wheel of Fortune
460 of 787Uraza
Loading description...
Games
Arrays
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.
The test case:
[ { name: 'Bob', scores: [ 10, 65 ] }, { name: 'Charlie', scores: [ 5, 105 ] }, { name: 'Bill', scores: [ 90, 5 ] } ]
is expecting "false" when the answer should clearly be "Bill." Interestingly, it's under the score validation category, but nothing here should return false. The description says:
"The winner one that is closest to 100 (while still being lower or equal to 100) ... Your solution should return the name of the winner or false if there is no winner (all scored more than 100)."
So, simply having one candidate go over the 100 mark is not sufficient for falsehood, only in the event that ALL of them break 100. Bill has the highest score here (95) without going over. I don't understand how this should be false.
The score for a single roll cannot exceed 100. Charlie's second roll (105) is not a valid input, hence it should return false.
The entire point of "closest without going over" is to eliminate only the players that go over ... It makes no sense otherwise. Why should one player's score invalidate my own?
Nowhere in the description does it say that scoring more than 100 qualifies as "invalid" input. The ONLY thing it says is that in order to WIN, the score must not be over 100. If a single candidate scoring over 100 invalidates the entire game for everyone, then the sentence
"Your solution should return the name of the winner or false if there is no winner (all scored more than 100)."
should say
"Your solution should return the name of the winner or false if ANYONE scores over 100."
I understand that there can be invalid inputs (floating point numbers, integers not divisible by 5, etc.). But there is not a single statement anywhere in the description that states that a score of over 100 is "invalid", only that it can't win. The rules need to be clearer. We shouldn't have to infer conditions. "ALL candidates must score more than 100 in order to have a winner." It's that easy.
It is written in the description that numbers on the wheel are multiples of 5, ranging from 5 to 100.
Correct, which is why non-multiples of 5 are invalid, because they literally cannot occur. Scores over 100, however, CAN occur. So they are valid inputs since they are possible to attain. Closest without going over should never mean that everyone fails even if just one person goes over. If instead, any score over 100 qualifies as invalid for the entire game, no matter the other scores, why not just simply state that? Why include the case that the game is false if "there is no winner (all scored more than 100)"? You shouldn't even need to state that case if a single >100 invalidates the game ... Look, the author gets to set the rules, I'm not disputing that. The only point I'm trying to make is that we shouldn't have to infer/deduce the rules of the game. They should be stated clearly unambiguously.
I think there is a confusion between the value of the different rolls of the wheel and the total score (sum of the rolls). A score over 100 can occur, but a single roll of the wheel cannot exceed 100.
There is no confusion on the scoring method, there is confusion in the statement of the rules. If a single over-100 score from a single player results in the entire game being returned "false," then why does the description even account for the case where ALL players break 100? This shouldn't even need to be brought up if merely a single score invalidates the game for everyone. If such an event should result in returning "false," then it should clearly state "ANY score >100 invalidates the game." Instead, when you say "The winner one that is closest to 100 (while still being lower or equal to 100)." And then say that it should be the "winner's name" or false if "there is NO winner (ALL scored more than 100)," there is nothing to say that a single player can't score over 100, only that they can't WIN. You can eliminate the need for either of these extra sentences by just stating "Any score over 100 should return false." Why make the rules murky? There are other comments from a while back that struggle with the very same issues in the instructions.
As for the logical/game-theory implications of the term "invalid," that's probably a separate discussion, but it seems odd to invalidate something that a player can do legally (i.e., spin the wheel twice). It's even more odd to invalidate and punish a player who legally scores 95 just because somebody else scored 110. Anyway, I just feel that the description could be made more concrete and clear-cut. I had fun solving it either way :)
If any single spin scores over 100, the entire input is invalid because scoring over 100 in a single spin is impossible according to the rules of the game. The situation described by the entire input is impossible. There are no players being punished, this isn't a game happening in real time, this is the results of a game being reported to your function. Because the input received by your function is impossible, the entire game is invalid.
What SHOULD happen to the contestants in such a game is outside of the scope of this function. In a real world scenario, if this would happen, it's likely that the game show runners would make everyone re-spin because the wheel was found to be invalid. Somehow, a wheel with a value above 100 snuck its way onto the show. Your function is not required to make this decision, the function is only specced to report this situation as invalid. If this were a computer game, as a programmer, you could conclude that you have a bug somewhere else in the code, or you could come to a conclusion that one of the players were cheating, but without more information, it's impossible to say who it is (and it wouldn't be the job of this function to determine the cheater anyway). In this case, you'd still want to report this game as invalid.
It's not a single score (score being the result of two spins) being over 100 that results in
false
. It's possible for someone's score to be over 100 (for example, if they got two 70's), this would not invalidate the game. It's a single spin being over 100 that invalidates the game (again, because this should be impossible, meaning something went wrong before the scores ever got to your function).You don't "roll" the wheel .... you SPIN it :-)
This comment has been hidden.
This comment has been hidden.
Can you not print the input to see why it's failing?
What do you mean by "not print the input"?
You can print the input of the tests, so you can see what inputs your code fails for. That's how you can "access the tests prescribed to a kata". The test log will show you what your function returned and what it was expected to return. You can use your own code to print the input of the test. That should be all the information you need.
Yes the test log shows what my function returned and what it was expected to return. But it doesn't show the input used in the test. How can I access that input?
You're using javascript, right? In the first line of your function, do
console.log(input);
I'll be damned,
console.log(input)
shows the input indeed! Thank you BobtheLantern, you've been the lantern of knowledge for me today, as you just saved me dozens of additional hours spent on figuring out bugs in my JS kata solutions... because I didn't know how to check the input LOL. Actually I asked this question in a few comments but nobody mentionedconsole.log(input)
, and you just showed me the code. My learning process will speed up from now on, thanks!this would have been fun if not for the incessant input validation
Ruby: no sample tests.
Added in this fork
Ruby 3.0 should be enabled, see this to learn how to do it
Enabled in this fork
Hmm??? Ruby random test ---
So how's that valid? isn't scores sum supposed to be lte
100
and that's what the fixed testinvalid input cases -> should check that scores are valid
is for?The sum of scores can be > 100. A player with score > 100 cannot win. Invalid scores are scores which contain invalid values (> 100 or not multiples of 5).
Please use new python test framework.
Done.
Why tests are ezpecting "Gandalf" here, while other players dont have any score? Shouldnt answer be
false
in this case?There is no test with the inputs that you mentioned. If I input your data to the kata's solution, it does return false anyway.
When submitting using Python 3.4.3 the following error occurs: "NameError: name 'xrange' is not defined" even though I didn't use xrange() in my code.
Switching back to 2.7.6 circumvents the issue.
Tests needs to be modified in order to use
range
sincexrange
has disappeared since Python 3.done.
I passed all the test cases, but when I submit I fail on the first one. Using console.log I get the input of the candidates array as: [ { name: 'Bob', scores: [ 10, 65 ] }, { name: 'Bill', scores: [ 90, 5 ] }, { name: 'Jennifer', scores: [ 55 ] } ] This test should fail because it has invalid input (Jennifer has only one score) according to the kata description criteria: "Please note that inputs may be invalid: in this case, the function should return false". However, it expects "Bill" as the right answer.
From the kata's description: "Each candidate can roll the wheel once or twice and sum up the score of each roll."
So it is perfectly valid for Jennifer to have only one score.
This comment has been hidden.
Did you check to see whether one of the scores arrays had an entry greater than 100? e.g. a scores array of [105,5] would need to return false for the entire function even if the other scores summed below 100 since you cannot attain a single spin result greater than 100.
tests are correct.
For test 14, I get 'Gandalf' in IDLE but on here it's failing for some reason. The program thinks I am getting 'False' for some reason.
Isn't that more of a problem of your code, then?
It is working in IDLE.
Then copypaste your code here (tick the spoiler flag before). Problem is certainly coming from your code, considering that tests are well-formed.
Also "It's working in my IDE" is not and will never be an apologize for coders ;-)
In the Ruby tests:
Has a typo, it should be 'rolled'
Fixed for all languages, thanks!
I assumed that having less than 3 candidates meant the game could not be played. I also assumed that the having no scores or less than 2 scores under 100 meant that the entry could be kicked out. Are those assumptions correct?
A candidate can have one score under 100 (if he rolled the wheel only once).
How do I get console.log to print out? Using the python version. Is it a command at the bottom of the code or at the top?
I guess a regular print will work for Python.
Can you clarify? I've tried using print in this interface and it doesn't return anything.
I just add
print(candidates)
at the beginning of the function and it prints out the list of candidates.I have passed the test case, but when i submit my code, feedback error : expected Bill instead of false. Why ??
There are more test cases in the validation step than initially provided with the kata.
You can print inputs using
console.log
to figure out what is going wrong.This comment has been hidden.
You should try again, I get this error when I submit your code:
ReferenceError: sum is not defined
.Thanks for the nice kata :), just one small suggestion for the Ruby description:
Replace
You receive the information about each candidate as an array of objects: each object should have a name and a scores array with the candidate roll values.
with
You receive the information about each candidate as an array of objects: each object should be a hash with two key/value pairs with the following keys: "name" and "scores". "name" is the name of the participant, "scores" is an array with the candidate roll values
Regrettably we cannot have that part of the description different from language to language, so I fear we will have to do with the test cases below.
Understood; thanks for considering my suggestion :)
Python and Ruby translation provided, if you want to approve them :)
Approved, thanks for the contribution!
Thank you for the kata and description update to accommodate also the new languages :)
@GiacomoSorbi
There might be a small issue with the Python random tests. I kept getting this
IndexError
but I wasn't accessing the items by index.I just resubmitted a few times and my solution worked. I briefly looked at the random test case code after completing the kata and noticed that is where there are items being accessed by index.
But I am having trouble deciphering exactly where the problem is. I am guessing it is somewhere in the
for _ in xrange(40):
loop since there are ~30 random tests passed before theIndexError
(it changes each time, this is just on the latest run where I could randomly raise the error).I enjoyed the kata in Python, just wanted to let you know since you could probably fix it very quickly!
Mh, I run it a number of times, even republished (which makes the tests many times more), and no problem; are you sure you didn't touch the initial array in anyway? Btw changed the code a bit to make it a bit more sound.
@GiacomoSorbi,
Sorry for the delayed response. I'm pretty sure I didn't touch the initial array in any way. I just iterated over it with a
for
loop and did not use indexes anywhere. I just submitted my code a few times again and on the 7th submission I get the sameIndexError
. Because theTraceback
is limited on Codewars (doesn't show the line) I took my solution and your test cases to do some tests on my machine.Although it could be argued that the problem lies inside of how you are generating the random values for
c
, I think it is a mix of that and how these next two lines are written (they are where theIndexError
's are being raised):These values for
c
were generated by your tests:I probably should have given you more detail like this the first time around. Although the problem only seems to come up randomly, it is still there and is reproducible.
Nah, I was also somehow absent-minded; I wrote a fix for that; interestingly, I again found no problem testing many, many times over, but it is ok, as I get that remote possibility.
@GiacomoSorbi,
Your fix seems to have worked like a charm! I ran 4 million random tests on my machine and not a single
IndexError
(or any other error!).I appreciate all of your hard work and effort.
Thank you!
Not much, and it would not be possible without such kind feed: thank you!
Did you mean to name this Kata "The Price is Right," because this is not how "Wheele of Fortune" is played? Just sayin.'
Yeah, those were my thoughts exactly.
Hello all,
I am getting an TypeError: Cannot read property 'length' of undefined at winner at one of my test cases. Has anyone encountered this?
I am setting winner = candidates[i].name which is accepted by the majority of the test cases except returns an error on one. Given that I am setting winner to a name, which is a string, I can't understand why this Kata is calling .length on it.
I would appreciate it if someone could tell me where I am going wrong with this.
I found the fix to this. My test for only 1 or 2 scores was before my test to ensure that each participant had a name and a roll, thus where this was not the case, I was trying to call .length on a non-existant property.
Hope this helps someone in my position.
Needs random test cases
A little bit more difficult than it seemed at first. It was interesting to solve it. Most time gone to check all exeptions. But good instruction were written, so I think this Kata is ready=)
Thanks, I am glad you appreciated it! :)
This is really a kata about error checking much more than a working algorithm. Perhaps you may want to inform the coders of what errors to check for rather than waiting to get flagged during the submit.
Thanks for the feedback, a list of error cases derived from the kata specification has been added at the end of the description.