6 kyu
Transpose of a Matrix
612 of 869debri
Loading description...
Linear Algebra
Matrix
Data Structures
Mathematics
Arrays
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Rust translation
Re-raising the issue: this kata is a duplicate of https://www.codewars.com/kata/52fba2a9adcd10b34300094c
true, but really? author probably didn't know about this and to just retire an active kata like that is kinda sad imo. still, we shall see what the people think so I won't close this issue now.
How is 798 solves in almost 10 years called "active"? That's actually a very pathetic number for a kata with the 3 most popular language versions (which touches the other issue I have with CW's kata suggestion system: lots of approved katas never see the light of day and it's always the same g964 crap getting suggested).
The linked duplicate has 6526 solves; if you're only counting katas based on how active it is (for whatever "active" means), you should see that it's 8 times more active and hence should be prioritized over this kata.
That kata's also created a year earlier than this kata, so it wins from time of creation standpoint too.
And anyways, no, the duplicate is non-negotiable, since the same solution passes both katas after accounting for certain unreasonable input validations.
@goldenratio161 There is a (slow) effort to handle duplicate kata, see here.
(This kata is already in the todo list)
This kata also has inconsistent specs of what is wanted between languages, it really should go imo.
JS: missing sample tests
Does this mean that, it won't work even if I provide solution? it's weird that i'm not even getting error message
There is only a stub present for creating sample tests. When you click on "Test" you don't get any error message because no test is run at all. But you should notice red triangles because
it
blocks are expected to have at least one assertion. The full test suite is present though so you can press "Attempt" to test your code.Python new test framework should be used (Refer this & this for more detail)
Ruby 3.0 should be enabled (Refer this & this for more detail)
It is not explained how to handle empty arrays, and transposing a
Nx0
matrix into1x0
makes no sense.Removed empty arrays and
Nx0
matrices for Python.Duplicate of Matrix Transpose.
Not in Python and Ruby. Throwing away those 100+ solutions seems unfair.
Shall we let this one be?
Closing.
The test cases in Python translation for different empty matrices are completely unneccessary, there is no point in it. Even more, they don't have any meaning from computing or the algebraic perspective and confuse the real purpose of transpose operation.
Fixed (don't know about other languages yet)
Kudos for the gif, although transposing and array with empty subarrays seems strange.
Yeah, well stolen from Wikipedia ..
Should be clear how to handle empty arrays, and arrays that contain empty arrays.
That seems to be the part to make you not just use the defaults.
As already pointed out,
[[]]
is a matrix with one row and zero columns, which is not really a matrix.Agreed. Can we please remove these test cases.
That seemed to be the point, otherwise you just use builtin's.
It could have been specified though.
Mathematically, a matrix with one row and zero columns makes perfect sense, and can be represented as an array, and a matrix with zero rows and one column makes perfect sense as well, but it cannot be represented as an array.
Ruby has a transpose function. This code
class Array end
passes the four self tests and the first seven kata tests.
It may be possible, but I wasn't able to overwrite ruby's native transpose method.
[[]] is a strange test. The "matrix" has 1 row and 0 columns, so the result should have 0 rows and 1 column which is not expressible with a list of lists and thus not reversible. I don't know why this test exists at all.
Basic tests 1 and 9 are contradictory, if you pass one you can´t pass the other. Test 1 says "[[]] should equal []" and test 9 says "[] should equal [[]]". Fix it please
It is solvable. The kata just expects [] if the array is empty and [[]] if the array only contains empty arrays.
so [[]] or [[],[]] would return [[]]
but [] would return []
I do however agree that this is an issue. The kata should either describe what to do in each case, or return the same value for an empty array and an array of empty arrays
Done. Thanks for the tip :)
That was a common issue, the description would have helped.
Some Examples Test Cases(in JS) will be an added star to the excellence of this kata ;)
There are examples.
There are some grammatical errors in the description, but this is pretty nitpicky since I don't believe it is enough to hinder comprehension
Some more destrcitption required on how to handle empty arrays.
Quite hard to solve since the test for transposed([]) should return different lists ([[]] and [])
Python tests contain both [] and [[]]. That's weird...
Ruby and Python translations submitted: if you wish to approve them, then post a reply to this comment, so that I can then edit the description a bit to better fit these two languages.
As usual, feel free to ask for more standard/random tests on JS too if you like my work :)
Random test cases added to the JS version and I took the liberty of adding a line to your code to handle edge test cases :)