Ad
  • Custom User Avatar

    Exactly as beautyistruth said, it works on closures and local loop scope.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Can you please explain why does it work so?

  • Custom User Avatar

    at the first round,It should be 'a' and 'b' were elimunated,rather than 'e',because 'e' did not show in the first round

  • Custom User Avatar

    at the first round,It should be 'a' and 'b' were elimunated,rather than 'e',because 'e' did not show in the first round

  • Custom User Avatar

    ok figured it out. The description could have been a bit less terse...
    The important line is "The votes are tallied from the each voter's first choice."
    I was throwing away each round's votes (i.e. shifting from the array). After elimination, you always should count the first preferences again.

  • Custom User Avatar

    I'm missing something... I've got the bit about eliminating canidates with 0 votes (i.e. collect all candidates before beginning the count). But what about this:
    [ [ 'b', 'a', 'e', 'd', 'c' ],
    [ 'a', 'd', 'e', 'c', 'b' ],
    [ 'c', 'a', 'd', 'b', 'e' ],
    [ 'c', 'a', 'e', 'b', 'd' ],
    [ 'd', 'c', 'e', 'a', 'b' ] ]
    Expected: c, instead got: a
    Round 1 a: 1, b: 1, c: 2, d: 1, e: 0
    e eliminated
    Round 2 a: 4, b: 1, c: 3, d: 2
    a wins?

  • Custom User Avatar

    Great fun! I think it was a deserved 2 kyu. It was hard-ish to debug. I was on a wrong track: I had the basic function in half an hour but I was combining the individual values to a single rgb value and then applying the weights, which worked for all but the last case which was pretty mangled. Not sure why this doesn't work. I thought it had something to do with normalisation and I think the question could have been clearer in this regard.

  • Custom User Avatar

    Loved it: spent a couple of commutes thinking about how to solve it. Thought I had a unique solution until I saw most did it like I did :)

  • Custom User Avatar

    Easy money :)