Struggling with the additional requirements to the transpose exercise on the JavaScript track

I faced a significant challenge while working on the transpose exercise in the JavaScript Track. This exercise proved to be quite valuable for me as it introduced me to a type of problem I hadn’t encountered before. Initially, I had to clarify my objectives and explore various ways to implement the solution in code. I found the solution shared on Stack Overflow to be immensely helpful.

As I progressed and experimented with different approaches, I grew more confident in transposing a matrix, having successfully done it in multiple ways. However, as I delved into the exercise itself, my struggle began.

If the input has rows of different lengths, this is to be solved as follows:

  • Pad to the left with spaces.
  • Don’t pad to the right.

Initially, I felt capable of meeting these additional requirements. However, after spending hours tinkering with my code, I realized that my existing knowledge of matrix transposition was insufficient. Seeking guidance, I turned to mentoring and studied community solutions. I managed to come up with a solution, but I still don’t feel like I fully comprehend the exercise.

I can transpose a matrix and apply the specific requirements, but I struggle to connect the dots between merely transposing and understanding the deeper patterns present in the mentoring and community solutions. To put it in terms of Chesterton’s Fence metaphor, while the exercise’s primary goal may be matrix transposition, the additional requirements seem to have a purpose that I’m struggling to grasp. I’ve noticed in other exercises that similar restrictions often lead to an “aha-moment” once I improve my solution. Yet, with the transpose exercise, I’m still left wondering why this particular fence exists.

I’m not advocating for the removal of these restrictions, as they surely serve a purpose. However, I think understanding the reasoning behind their inclusion would significantly enhance my comprehension of this exercise.

Any insights or explanations that shed light on this mystery would be greatly appreciated.

If you’re approaching this exercise as a “this will teach me to transpose a matrix” … you’re looking at the wrong exercise :slight_smile: This exercise may relate to matrix transposing and/or build upon it, but it is much, much more involved and nuanced than a regular “transpose this matrix”.

This exercise has some pretty tricky requirements with padding, where padding is required. However, you can’t pad to a uniform length. Instead, you need to pad lines such that a line is never longer than the prior line.

@IsaacG thank you for your response! Yes, this was exactly my journey, in the beginning I had the thought that “this will teach me to transpose a matrix”. But as I tried to explain, the requirements that you mentioned have been the point where I had to realize that this is a much trickier exercise then just transposing a matrix. And as I mentioned I also was able to solve it. But still I’m left with the feeling that I don’t totally grok the exercise. In that sense that at all the other exercises I was doing, the imposed restrictions had a purpose that I could clearly understood, at least after I was able to solve it. In that sense most of the time they followed a pattern like: “If you use this pattern or try to approach that problem, keep these edge cases in mind” et cetera. This kind of didactic is what I don’t see in the mentioned restrictions of this exercise. Based on my experience with the other exercises I assume that I’m missing out on something respectively that there was a specific didactic reasoning behind imposing those restrictions.
I don’t wanna state that it is a problem, to add restrictions without explicit didactic reasoning, but to add a little puzzle. I just wanna make sure that I don’t miss out on anything. Because based on the experience with the other exercises i got this impression.

I hope this clarifies my question further.

Exercism, as a whole, takes a Test Driven Development (TDD) approach. The detailed requirements are often not fully expressed in the prose but are encoded in the tests. Some of the harder exercises (like this one) may have some really finicky requirements which can only be discovered via the tests. The tests enforce a strict expectation of what the output looks like for a wide range of input shapes. There’s no secret grand explanation or lesson behind those requirements that you’re missing.

I’m aware of the TDD approach and also that taking a look at the written tests give me a better insight into the requirements of an exercise. I’m unsure if that is an misunderstanding, but just in case I don’t have any troubles in acquiring the requirements of the transpose exercise.
Did I understood you correctly, that you wanna state that there is no didactic reasoning behind modifying matrix transposition with the given requirements? I don’t mean this question in a rhetorical way. I totally think that this is possible that there is no such reasoning! :upside_down_face: And I’m also aware that it is really hard to make an argument for the absence of such reasoning. Therefore I’m interested in opinions about this. Also I would like to clarify that I use the term “didactic reasoning” in a very broad way. So I don’t expect that this requirements introduce a new concept, idea et cetera. But I can imagine that there was some reasoning to create the exercise the way it is.

Correct. As far as I am aware, there is no didactic reasoning to the requirements in this exercise. They are arbitrary requirements and may even be chosen specifically to make this exercise more challenging.

The exercise source points to reddit/r/dailyprogrammer which credits it to u/Gommie.

I can’t speak for the requirements specifically but if you’re wondering what possible use-cases there might be for truncating the right side only, one would be for storage/transmission optimization.

Suppose we instead of working with 3x3 matrices, worked with 1000x1000 matrices.

In e.g. large stochastic matrices, almost every cells could actually be zeros. Zeros to the left of non-zeros do serve some purpose, which is to align the non-zeros to the correct column (if the row was represented as an array/string). However what would be the reason for storing/transmitting all the remaining zeros on the right side? Supposing most of our 1000-sized rows are zeros, it would be a waste to transmit in its entirety, instead of implementing a rule that says “hey, if a row ends prematurely, the rest of the row would be zeros only”.

We intuitively do this for numbers as well. E.g. round(1.123456789, 4) would yield 1.1235, but round(1.120000000, 4) yields 1.12 even though we ask for 4 decimal precision. The remaining zeros are implicit.

Hopefully I understood your question, if not I apologize! :slight_smile: