I’ve tried solving this in JS and I pass all the test cases and 4/5 validators, but not #3 “Too much votes_validator”.
My code looks pretty solid and it isn’t of course hard coded in any way. I tried handling wide-chars as a current trend in the community puzzles seems to be using these without saying so (e.g. 7-segment display and snake encoding), but this didn’t make a difference.
Does anyone have any thoughts on this? I’m not looking for a solution just any indication if this validator requires something weird or unexpected (or alternatively confirmation if anyone solved it in JS without any weird stuff).
[Edited: don’t believe me, there is a proper solution that passes test and validators, see update below.]
Watch out! For the so-called complex test case (#5) the test that you can run in the ide differs from the one that is used when you submit your code. Your solution has to fail test #5 in the ide to have a chance when submitted. You are actually expected to output "4 2" for such an input: 4 8 Albert 2 Roger 1 Valérie 3 Thierry 1 Albert Yes Valérie Yes Erwan No Albert No Thierry Yes Valérie Yes Valérie No Valérie Non
Thank you. What a mess. So, the rule the “voter voted more than he is allowed to (all his votes are invalid” is not properly treated in validators, but is in test cases
My apologies to the puzzle designer and validator… the mistake was mine and once I read the puzzle description properly I was able to get 100% on the puzzle.
I was disqualifying voters if they didn’t vote exactly the number of times stated in the input, when in fact the puzzle description says to disqualify voters who vote more times than they were allowed.
I think I’ve just had a bad experience with the community puzzles not acting as described and am now too hasty to suspect that a community puzzle must be faulty.
As for finn_troll’s comments: thanks for trying to help but my experience doesn’t match what you have described e.g. my code passes test #5 and validator #5 equally well.
First my code removes anyone who voted too many times (i.e.Valérie), and anyone not registered to vote (i.e. Erwan); then it counts remaining yes votes (Albert 1,Thierry 1, total 2), and then the remaining no votes (Albert 1, total 1). The maybe/non votes are never counted.
The description says to wipe a person’s votes if they vote too many times, but does not say to do that if they vote something other than Yes/No. However, the 5th test case only passes if I do wipe a person’s votes for voting something other than Yes/No. I think that needs to be clearly stated in the description.
@numbermaniac@TwoSteps Note that there is a typo (that we cannot fix) in the last test (there are 9 votes given, not 8, even though that doesn’t change the result as the last vote is invalid).
I don’t think this is related to your problem though: You have to remove Erwan as he doesn’t appear in the list of voters and Valérie, not because she voted “Non” once, but because she voted 4 times.
I have an issue with this puzzle. All my tests pass in the ide, but when it comes to validators, the 5th one keeps me from getting the 100% holy graal.
— Python3 —
Here is how my code works. I first check if the voter is in the list of voters, and if it is, then I check if the vote is valid (“Yes” or “No”).
If the vote is invalid, I still count this vote and decrement the counter of votes the voter is allowed to make.
If the vote is valid, I increment the right value to the corresponding key in my dictionary (keys => “Yes”, “No”)
If someone tries to vote more than he/she is allowed to, I delete all her/his votes. As an exemple, if he/she has voted [“Yes”, “Yes”, “No”], then in my dictionary, I decrement the value at the key “Yes” 2 times and decrement the value “No” one time. If a person votes something else than “Yes” or “No” and votes more than he/she is allowed to, I also delete all/his votes. Which allows me to pass the 5th test in the ide.
I can’t see what I’m missing. If there is a generous soul to tell me what I might be missing, that would be nice :).
Not sure I get this part since the second condition is a sufficient condition to delete all votes of a voter. But a vote other than “yes” or “no” doesn’t invalidate all votes of a voter. Is it clear?
I preferred to filter invalid votes before counting them. Maybe it’s simpler than decrementing votes that you’ve counted already.
Thanks for your answer, I’m sorry if I’m not clear, reading english is easier than writing it :).
— English —
To illustrate that sentence you didn’t understand, I’m gonna talk about the fifth case. Valérie has the right to vote 3 times. Her first 3 votes are [“Yes”, “Yes”, “No”]. All those votes are valid, but she has the nerve to vote a 4th time with a “Non”. Since she tries to vote 4 times when she is only allowed to vote 3 times, I cancel all her votes. Even if her last vote is invalid.
— Français —
Pour illustrer mes propos et cette phrase que tu n’as pas compris dans mon anglais des beaux jours, je vais prendre un exemple : le 5ème test :D. Valérie a le droit de voter 3 fois. Elle vote [“Yes”, “Yes”, “No”]. Tous ses votes sont valides. Mais la petite tricheuse s’autorise un 4ème vote “Non”. Quand bien même ce vote est invalide, je le compte comme si elle avait voulu voter 4 fois et j’annule tous ses votes.
Du coup, tu me dis que je ne devrais pas prendre ce 4ème vote comme un vote en trop?
What I’m saying is that whatever her fourth vote (be it “No” or “Non”), all her votes have to be cancelled if she’s allowed only 3 votes.
Your logic seems ok. That’s why I suggested to filter invalid votes then count. Even better: filter invalid voters, then invalid votes, then count.
The way I write my code is to first sort the data into a few lists and/or dictionaries for easier management. Then, I check to see if the number of votes casted by a particular person is the same as the number of votes s/he can use. If yes, the code continues; if no, all votes casted by the voter is removed from the list. Finally, I count the number of yes/no votes and print the count.
I managed to pass all the test cases. I actually substantially modified my codes on deletion of invalid votes and they still work on the test cases… but still can’t get 100% with the final validator… I wonder whether anyone made it through…