Beta

Seat Allocation Double Dutch

1 of 19FrankK
Description
Loading description...
Mathematics
Algorithms
  • Please sign in or sign up to leave a comment.
  • Voile Avatar

    Python (probably other languages also) too: modifying input can influence the random tests: see this

  • monadius Avatar

    Python (probably other languages also): Proper random tests are required. Solutions like this one should not be possible.

  • gaziz Avatar

    What a painful kata! Like it!

    It says that I have the ability to edit/approve the kata, but I'm a little reluctant to muck about with approving/editing/creating things. I would like to first get more comfortable wth the established codewars processes, policies, conventions etc. Hence not yet a single kata done by me.

    Would any of the power users be so kind as to give me a rundown of what's ok and what's not in terms of editing/approving katas, etc.? Or even just point me to the right documentation perhaps?

  • IVBakker Avatar

    Hi could you be more descriptive/example for the combinations:

    • Forming an alliance is a possibility for smaller parties to mitigate their size disadvantage in the assignment of residual seats.

    -> OK

    • A combination is treated as 1 party but after the standard allocation the seats gathered by the combination need to be allocated again to its individual members.

    -> OK

    • The votes needed for a seat (quota) is the total votes of the combination divided by the seats assigned to the combination.

    -> so if a combination with 100 votes (which correspond to 10 seats) has 2 parties A and B. A who got 70 votes will have 70% of the combination seats (7 seats) and B with 30 votes will get 30% of the combination seats (3 seats). Am I right?

    • Residual seats are assigned to the parties of a combination based on the largest remainder of votes per seat.

    -> I don't understand where the residual seats come from

    • FrankK Avatar

      Hi,

      It is always a trade off how much to tell and how much not to tell. You have to do a little more thinking yourself in this kata, just as I had to do when I created it. At least you have the same amount of data as I did because I added a link to a Wiki page in English language.

      The residual seats are hard to understand, but interesting. And there are two different mechanisms (that's why I called it 'Double Dutch'):

      • INITIAL... Let's say that one by one you calculate who is left with the highest average number of votes per seat IF a party (or combination) would get the seat. A party can theoratically get for instance 5 residual seats.

      • Within a COMBINATION (your question). Here a party can only get 1 residual seat. Seats go to the parties with the highest residue of votes.

      Combination example:

      Total seats gained by the combination: 10 Allocation:

      • A: 1.05 seats
      • B: 1.66 seats
      • C: 2.65 seats
      • D: 4.64 seats

      Then the correct result would be for the combination (1+1+2+4=8 seats allocated immediatly):

      • A: 1.05 = 1 + 0 = 1
      • B: 1.66 = 1 + 1 = 2 (got the first residual seat because 0.66 is higher than 0.65, 0.64 and 0.05)
      • C: 2.65 = 2 + 1 = 3 (got the second residual seat because 0.65 is higher than 0.64 and 0.05)
      • D: 4.64 = 4 + 0 = 4
    • IVBakker Avatar

      I see, that's what I was feeling. It's simply the way to deal with rounding when working with floating numbers.

      Few changes I would expect:

      • explain that residual seats are seats that are still left to allocate due to rouding
      • a more visible link to the wiki page
      • say that the "D'Hondt method" is used for the highest averages (there are more than one highest average method)
    • Jomopipi Avatar

      You have to do a little more thinking yourself in this kata, just as I had to do when I created it

      OK, but trying to understand the description should never be part of the task.

    • dfhwze Avatar

      Yeah, this description is a pain. Also allocating the remaining residual seats after combinations have been handled is a complete mystery. I wanted to solve this kata out of loving memory for Pim, but F it, just not worth it.

    • FrankK Avatar

      Everything you need to know is in the description. Just read better. From my 30 years of experience that is sometimes hard for developers (also when I read the comments here).

      And yes, kata is hard. I did the kata myself too and had a problem with it.

    • dfhwze Avatar

      Don't patronise me, in my long career I've always challenged bad specs.

    • FrankK Avatar

      You don't want to be patronized?

      I tried very very hard to understand what you do not understand. Everything is written down. What is not to understand about the line below? Is it maybe the word 'standard' that you read as 'allocation of seats excluding residual seats'? No clue, the sentence below talks about 'standard allocation' as opposed to 'allocation within combination'.

      'A combination is treated as 1 party but after the standard allocation the seats gathered by the combination need to be allocated again to its individual members.'

      Keep opposing bad specs! You will not find them in this kata.

  • Blind4Basics Avatar

    Hi,

    Could you provide in the descriptoin the votes data array that leads to the table at the end? Because I have troubles to understand the instructions.

    thx

  • ThomFabian Avatar

    Thanks for the kata. I have a quick question. The decriptions says:

    Parties without enough votes for at least 1 seat are excluded for remainder seats and cannot be part of combinations.

    What is to be done if a member of a given combination does not reach the "at least 1 seat" standard? Is it simply removed from the combination? If so do it's votes still count toward the combination? Or does the combination dissolve? None of the immediate test cases seem to look at this situation, and maybe it's not important, but I wanted to know before I get too far into addressing that edge case. Thanks

    • FrankK Avatar

      Hi Thom!

      At first my respect for you! Nice clean solution. This is not an easy solution :)

      You probably already know the answer by now. But the answer is (when creating the kata I also had a problem finding out):

      • If a party does not have enough votes in the standard way, the party cannot participate in a combination and the votes are NOT counted for that combination.

      I can declare you an official expert on the Dutch voting system now! ;) I do not a single person who know how it works here in The Netherlands. Just for the record:

      • In the 2017 elections it is no longer possible to do combinations. That makes the calculation a whole lot easier and less interesting...
      • Due to the Dutch election system we need now (2017) at least 4 parties to get a majority and to form a government. I do not know if other countries should fancy a system like ours with the very low threshold.
    • ThomFabian Avatar

      Hello Frank,

      I actually quite enjoyed the kata, as I like to learn new systems and understand how they work. I'm sure there are very interesting stories as to how the current system came about. I can only imagine the discussions and debate about each step in the process. It's quite intersting to me as an American where we basically get to pick from Column A or Column B for the most part.

      As for the Kata, perhaps I'd suggest you just mention you above answer as to how to handle combinations (or mention that no tests will cover this condition, and thus folks can assume all combinations only contain parties that meet the threshold).

      I also found this link Wikipedia : Elections In the Netherlands to be helpful in understanding the seat assignments as an outsider. It may come in handy for others as well.

      Thanks again for the kata, I enjoyed it. My code is, as per usual for me, not concise or perhaps the most efficient, but I tend toward more verbose code that seems, at least to me, easier to read. Thanks again and cheers.

    • FrankK Avatar

      Hello Thom,

      Thanks for your link! I used it in my description.

      I find it very interesting, comparing the Dutch system and other systems like the English and American.

      Sometimes I get influenced by this website too and try to write also one liners and 1 character variables. But really complex problems, in my humble opinion, can only be solved by well structured and readable code. Cheers!