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.
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).
This comment is hidden because it contains spoiler information about the solution
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
This comment is hidden because it contains spoiler information about the solution
This solution has high readability but requires copying matrix elements by value way more than necessary.
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.
This comment is hidden because it contains spoiler information about the solution
...except that Array.new() throws an error if given a negative integer and we need to rescue that as well.
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).
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.
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.
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.
This is simply gorgeous.
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.
The server is fast enough for a properly optimised algorithm. I should know since I just solved this kata in python. Research memoization: http://stackoverflow.com/questions/1988804/what-is-memoization-and-how-can-i-use-it-in-python
Loading more items...