Ad
  • Default User Avatar

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

  • Default User Avatar

    There are several groups of test cases. One group is for low positive numbers. These are largely fixed (i.e. fib(0), fib(1), fib(10), etc) but some are random. Another group is for low negative integers, again, some fixed and some random. The last group is for higher n, generally n > 1000, with the last two tests for n > 1,000,000. Like the other groups, some inputs are fixed and some are random. This last group has the tests that tend to timeout. Note that failing anything within a group stops the testing at the end of the group. In other words if you fail something in the low positive numbers group, you don't ever see any tests from the negative or high positive numbers groups.

    While your algorithm may be correct, if you are getting timeouts you may want to try some testing on you local machine. If fib(1000000) takes more than a few seconds, your algorithm is probably too slow and you need to rethink it.

  • Default User Avatar

    Do they run secret test cases? For example, fib(1000000)?? My code is mathematically correct, and seems like it should be plenty fast enough, but when I insert
    return fib(500000) if n == 0
    at the top of the function, it times out.

    If this is the case, I guess I need to optimize for speed, but it sure seems like my code should be fast enough. There should be no stack issues, either, as I'm iterating, not recursing. Perhaps is it the shear size of the result that is a problem?

  • Default User Avatar

    This is really interesting, because I started a statewide group in California, called Californians for Electoral Reform, about 20 years ago that promotes IRV and Proportional Representation. I also wrote software ("ChoicePlus Pro") used by the City of Cambridge to count their ranked ballots. IRV is being used in Minnesota, California, Massachusetts, and some other states last I heard. The best national source for more information is FairVote.org.

    The Description given is sufficient, although minimal, except perhaps for the last two bullet points. What happens is that each round you eliminate one or more candidates (the ones with the lowest vote total), distributing their votes to whoever is next on their ballots. So if my ballot is A, B, C, and A is eliminated, then my vote now goes to B. If B is eliminated, my vote goes to C. If everyone is eliminated, the vote is exhausted. After distributig votes, you check to see if the winner has a majority of the remaining votes. If you get down to two voters, the winner is the one with the most votes.

    And yes, you only look at the 1st place votes initially, though subsequent rankings are used when candidates start getting eliminated.