[Community puzzles] Vote counting

Hi all.

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).

Cheers,
Russ.

I have the similar problem with C, only this time on the last validator. The code sllok pretty OK to me.

[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

1 Like

Thank you. What a mess. So, the rule the “voter voted more than he is allowed to (all his votes are invalidis not properly treated in validators, but is in test cases :confused:

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.

1 Like

What is your output for test case #5 then?

Hi Finn.

My output is 2 1 as the test case requires.

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.

Thanks to your input, I also have the proper solution now. The key was to

  1. not completely disqualify voters for invalid votes - this allowed my solution to pass the validators
  2. do count invalid votes to the total of the person - this allowed my solution to pass the tests as well =)

Hi there,

I can’t understand what happen,
all the tests pass,
but during submit, the last one failed…

It does not matter a lot, except that i can’t sleep anymore :smiley:

if anybody has a clue ?

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.

Is it not clearly stated though?
If the vote is not yes or no, it’s invalid. You’re asked to print valid votes so you don’t have to print such votes.

 Your program must output the number of  **Yes**   **No**  valid votes.

    [...]

    One vote is invalid if :
    - it is neither  **Yes** , nor  **No** ;

@numbermaniac @_CG_Thibaud 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.

1 Like

i found it and pass ide and validators… read carefully the states of the problem about disqualifying votes or voters…

Hello dear codingamers,

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 :).

Thanks for your time!

Foxx py :smiley:

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.

Thanks again, I changed my algorithm the way you told me to and it works. I pass all the tests in the ide and in the validators.

I have a little trouble to see exactly where the issue was in my code, I guess, my function that deleted votes was not well programmed.

You rule, man! :smiley:

This will be my 16th episode on my youtube channel and I’ll make sure to thank you properly for your help! :slight_smile:

1 Like