problem-specifications
problem-specifications copied to clipboard
Improve Problem description for Rectangles
The Rectangles problem asks users to count the number of rectangles in an array of ASCII text. In the problem description, an illustration of such an array is given, and its valid rectangles are called out.
However, there's a sentence at the end of the problem description that seems unhelpful:
You may assume that the input is always a proper rectangle (i.e. the length of every line equals the length of the first line).
What does this mean? It's confusing because:
- The sides of the rectangles do not need to all be equal (that's a square of course, which is a special case of a rectangle.)
- The "first line" means what?
I would propose that this sentence simply be removed, since knowing what a rectangle is seems pretty fundamental, and this sentence doesn't make anything clearer. If for some reason there needs to be explanatory text there, I think it should be helpful and unambiguous, perhaps like:
A rectangle's opposite sides will be both parallel and equal to each other in length. A rectangle's adjacent sides may or may not be equal to each other in length. You can see in the above examples that some rectangles have a height that is equal to their width, and some do not.
Or maybe the sentence is intended to convey something different than what a rectangle is? If that's the case, then I still think it could be clarified to communicate whatever is actually intended.
I read it without any indication that there is a number of lines (for the vertical length of the rectangle) that is arbitrary, but the length of those lines must match the length of the first line. Otherwise it is a rhombus. If it were a square then the specification, written, would say that the number of lines must match the length of the first line, which would provide us with a square.
The first line means, the first line. I am not sure why that is not clear.
Perhaps, though, I can agree that this line does not need to be there, we can enforce, and clarify in the tests.
The tests, which are meant to be read, may clarify the meaning of the written words. And while the tests do not have to be exhaustive, (and most often should not be) the reading material should never contradict the tests.
Also, thank you for the opportunity to talk about this exercise!
For an input like:
+-+
| |
+-+-+
| |
+-+
those instructions indicate that the last two lines will be padded to the right with spaces, thus making all lines in the input equal length (five characters per line), rather than the first three lines having five characters and the last two lines having only three.
Presumably, the student is spared the possibility of having to check for and prevent an index out of bounds.
Well, now it makes sense in the context of the input format! Maybe no change is needed, or something simple like:
You may assume that the length of every line of the input will match the length of its first line.
And/or a test to validate that?
I'm happy to create a PR if a change would be helpful. If not, I'm equally happy to close this issue.