7 kyu
The 'spiraling' box
823 of 1,952brodiemark
Loading description...
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.
Scala assertion messages are unreadable.
Please provide formatted assertions for kata like this, especially white ones.
For the random tests, the assertions are things like:
"Test Failed: For m = 70, n = 13 → Value at (11,1) incorrect; expected 2 but got 1".
I think that's pretty readable, and I think it's preferable to printing out the user array and the correct array, which could be quite large.
For the sample tests, the user can see the correct array in the editor, so I'm not sure why a formatted assertion is needed there.
Because the user can't see the output of their function formatted?
You should also at the very least provide small random tests with formatted output too, even if you do custom messages for the big ones.
They can print the output of their own function.
Ideally, yes. But this kata was in the early days of my authoring, and I didn't know then what I know now. The problem is all the translations are consistent, so if I do it for Scala, I have to do it for all of them. You're asking for a lot of work :-(
I'll personally fix it for Scala/JS/Python.
Another time the code don't work here but in VSCode is perfectly fine. I'm stocked at the beginning trying to create a numpy array of (n,m) shape but it gives me error and i don't understand how to fix it.
Here's the code:
def create_box(m, n): arr = np.ones((n, m)) return arr
Here's the error: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Can someone give me some advice on how to bypass that problem? Thanks in advence.
Do you import np correctly ?
Yes, of course. I omitted that but i did as follows: import numpy as np
This usually happens when you test your solution in VSCode incorrectly.
Your solution is expected to return a list, and not a numpy array. It's not really a kata issue, however, arguably, assertion message could be better or the problem could be hinted in some more explicit way.
You need to fix your solution, and you need to make sure that you are testing your solutions in VSCode correctly.
First of all thanks for you explanation. Anyway i'm using the same exact code in VSC and it works, and also, in the task explanation it is written "fill a two-dimensional list (or array)", thus, i expect eather array or list would be ok to use.
I'll keep trying with different approach though.
Since descriptions for kata are shared by all languages, you sometimes get sitations like this. What is called a list in python is called an array in other languages. If you see something asking for an array, 99% of the time it will be referring to a list in python.
Haskell translation
approved
Thanks!
( JS )
Tests should have
chai.config.truncateThreshold = 0
I added it. Everything seems to test fine, but when I try to publish, the message “Kumite published with failed tests” appears. Not sure what the issue is (I'm not very familiar with JavaScript testing).
I can't find your fork, so I really don't know where tests are going wrong.
I published a fork that should solve this.
Thanks.
guys, please give me a hint on how to approach the problem.
One way is to look for a formula that, given i and j, returns the value in the array at position i,j. In row r, the elements increase from 1 to r in the first r columns, remain at r until column r from the end, and then decrease to 1. By comparing the row and column value appropriately, you can figure out what the array element has to be.
you work indivudally and don't use chatGPT and you're the best coder in the world bro
The kata is underrated - strong 6kyu.
Agreed.
Rust translation
Thanks for the translation! It'll take me a few days before I can take a look - I'm a college professor, and Fall semester classes have just started, which is always a very busy time. Also, I'm not familiar with Rust at all.
Approved by someone.
I approved it. I like the terse style.
One very minor suggestion: in (0..m).map(|i| *[i+1, ...],
make the spacing around * consistent, either (0..m).map(|i|*[i+1, ...] or (0..m).map(|i| * [i+1, ...]
I love functional Rust :)
The asterisk is the symbol / operator to dereference the result of
...min().unwrap()
, I always saw it stuck to the variable it dereferences, and there is usually always a space between the|...|
holding the variables of the closure and the rest of the code, so I would not add nor remove a space here.Makes sense - thanks.
I find the naming of arguments in C# utterly confusing. The name
length
does not seem, at least to me, to be a good complement ofwidth
. The "length" and "width" seem to overlap in meaning, and I am not sure if "length" applies to rectangular matrices at all. I would suggest renaminglength
towidth
. With current setup, it's difficult to tell what argument relates to what dimension of the output matrix.The naming of the arguments was discussed when the kata was first approved, and I have tried to be consistent in the translations since then. @hobovsky, are you suggesting that only the C# version should be changed, or does your suggestion apply to other languages as well?
I mean, it can be just a language thing and feel free to ignore my remark if I happen just to be English-stupid. It's just that I had real problems determining from the description what dimension of the box is
width
, and which islength
, because I have no clear understanding what would be a length of a 2D rectangular shape. The description and submission tests seem to useheight
and notlength
.Maybe the fact that most languages uses a row-major definition of a 2D array, and the fact that the outer array of rows has some length, is enough. Although I am not sure if this works for 2D arrays in C#, because there is no outer array which would have a length.
I am not a native English speaker, so I have no good proposal how to clear things up. I will be fine if you just declare this a user problem and dismiss the suggestion. I just wanted to let you know that the
length
thing actually confused me to the point of checking sample tests, because I could not figure out the requirement just by reading the description.width
andheight
would be clearer to me because that's how I am used to think about matrices and other kinds of "rectangular sets of numbers", like images etc.Would it make it easier to grok if it said "given c (number of columns) and r (number of rows) .." - I usually find it easier to talk about R and C when discussing 2D structures. I didn't have any problems understanding this kata's instruction but it was mainly the samples that I used to understand it rather than the description ("first and last row and column" isn't the clearest way of describing the 4 options of "first row", "last row", "first column", "last column" options, I think)
I renamed the parameters in the initial C# solution to m and n, as in the description. I think this is one of those cases where single letter variable names might be preferable. And I modified the error messages to refer to width and height, rather than length. Hopefully this will clarify things.
I got to the point where all tests I run on the IDE work as intended, but it still comes up false here (C#) This has been my favourite challenge so far though.
But why is this a kata issue? Did you find a bug in the kata? What bug is this?
Can you give an example of a test case that comes up false?
@GareBearino, I can't really investigate the issue unless I have more information, like a test case where you think the result is wrong. Otherwise I need to mark the issue as resolved.
I'm going to mark this issue as resolved because I see no problem with the kata.
Чё то сложновато для 7kyu;
Probably the toughest 7Kyu I've done, was stuck with an off-by-one error! Enjoyed it, thanks.
It was my first attempt at authoring, so I might have underestimated the difficulty!
Beta testers deemed it 7kyu aswel. It does seem a correct assessment of the difficulty of this task.
yeah that's fair enough, I've certainly done much easier 6kyus though. And I guess it's all relative anyhow, I found this one probably more difficult than I should have.
This comment has been hidden.
Are you referring to the function name create_box, or to the examples of return values? I changed the description to not show an explicit function name, although I'm not sure that that's clearer. More specifics concerning what you would like to see would be helpful, thanks!
Maybe you can replace the word
input
withgiven m = ..., n = ...
. Would be clearer I'll sayDone
This comment has been hidden.
The first parameter is width and the second length. But it looks like you have that in your code. Is your solution passing or failing the tests?
C#:
Done.
C translation
thanks !
you have very long lines in the tests suite. when the lines are longer than some threshold, syntax highlighting is disabled for the whole program, which makes translating/maintaining/reviewing harder. I suggest you re-indent the offending lines, to activate highlighting
Done.
Hi, not really a spiral ?
I couldn't think of a good name (and I did put 'spiral' in quotes :-)). When you make n a little larger it sort of spirals into the middle, maybe.
Maybe Russian dolls :) is more appropriate
onion layers
Funnel. Gravity well. Square based pyramid contour lines. Journey to the centre of the square earth, that is flat, and stands on the back of 4 elephants atop a star turtle :)
The switching of the traditional row, col ordering caused a real headache. Might wanna do a flipperoo.
I added the meaning of
m
andn
in the description to avoid similar headaches for future solvers. Changing the order of arguments is no longer a viable option after approval. Ok for you?Assertions need to use the updated test framework.
I fixed the issue, and added diagnostic messages for errors. But it doesn't allow me to re-publish, so what do I do now?
You can only republish once all issues have been solved.
you need to set this as resolved -> now you can republish
So is the author supposed to set the issue as resolved, or the reviewer?
Usually the author, or a user with the "resolve comments" privalage.
Random tests should be generated on the fly, not chosen from a small set of inputs.
(Also, 3 random tests are far from enough. Usually around 100 is advised)
It wasn't clear to me how to create true random tests without using the reference solution.
(Scratch that - it just occurred to me. I'll do it once I get time.)
The "reference solution" isn't actually one; it's just a lookup table.
Not sure where you took the code from, but it probably comes from very old katas, and they did not do random tests properly. Newer katas usually have proper random tests.
I was trying to follow the "Example test suite" in https://docs.codewars.com/languages/python/authoring/#imports . Should I do something different?
I fixed the issue, and added diagnostic messages for errors. But it doesn't allow me to re-publish, so what do I do now?
you need to set this as resolved
This is almost the same as https://www.codewars.com/kata/58b8e11f60873d9068000110
Would it be worth creating this one as an easier version (since it doesn't have the length restriction) and then pointing people to the harder one?
If this gets a JS translation, surely it would get spoilers for the other one. So I think it can be approved, but without a JS version, just make sure to link to the other kata.