Ad
  • Custom User Avatar

    It's been a long time since I worked on this kata (I'm not even sure where the copying by value is taking place anymore although I would assume that it's the array parameter being passed to the determinant function recursively), but my solution looks like it calculates the determinant without copying any values (and certainly not creating entire temporary arrays).

  • Default User Avatar

    really?what's the alternative method?

  • Custom User Avatar

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

  • Custom User Avatar

    Haha, this is almost exactly what I came up with from looking at Wikipedia. First time Wikipedia has ever helped me find a simple solution. xD

  • Custom User Avatar

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

  • Custom User Avatar

    This solution has high readability but requires copying matrix elements by value way more than necessary.

  • Custom User Avatar

    It depends. If you want a O(1) space complexity, sorting is required. If you have extra space available, you can use my solution, which has a time complexity of O(a+b) as opposed to sorting's O(n log n) complexity.

  • Custom User Avatar

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

  • Custom User Avatar

    ...except that Array.new() throws an error if given a negative integer and we need to rescue that as well.

  • Custom User Avatar

    I agree that Hash resulting from a proper solution to this kata would be an obscenity in production code, but I would still suggest people try to solve the kata in order to see how well they understand ruby. I tried, failed, and learned some things in the process (My thanks to @ineiti).

  • Custom User Avatar

    I really feel like you should unspoiler your comment since your point is one that only seems obvious in hindsight. That, and that fact that tests are actually cumulative which means that it was actually unseen issues with Test 4 that were causing Test 5 to fail.

  • Custom User Avatar

    Apparently, the logic is that your algorithm is supposed to collect the names of all candidates before checking vote totals. Therefore :c would have been eliminated in the first round because :c recieved 0 votes.

  • Custom User Avatar

    Apparently, the logic is that your algorithm is supposed to collect the names of all candidates before checking vote totals. Therefore :c would have been eliminated in the first round because :c recieved 0 votes.

  • Custom User Avatar

    This is simply gorgeous.

  • Custom User Avatar

    Crus-T's point makes sense, but it would have been a lot easier to figure out that logic if we had been given an array of all the candidates names along with the voter preferences.

  • Loading more items...