Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Exactly as beautyistruth said, it works on closures and local loop scope.
This comment is hidden because it contains spoiler information about the solution
Can you please explain why does it work so?
at the first round,It should be 'a' and 'b' were elimunated,rather than 'e',because 'e' did not show in the first round
at the first round,It should be 'a' and 'b' were elimunated,rather than 'e',because 'e' did not show in the first round
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.
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?
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.
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 :)
Easy money :)