6 kyu
Multiplication table
14,540 of 43,186Bugari
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.
This comment has been hidden.
Cool Kata, thanks. I had to read the description 3 times before I understood what was being asked. It wuold really help to provide an example of a 4 x 4 matrix as well.
In Javascript, Node 18 is enabled, but tests don't use chai, causing a deprecation warning on test and attempt.
Fixed in this fork
This comment has been hidden.
You are returning a numpy array, but the tests expect you to return a list of lists. They are different data-types and they work differently. The tests are basically comparing your return value to some expected value like this:
your_answer == expected_answer
, and if that expression results inTrue
, you pass the test. When you compare two lists likelist1 == list2
, you get a single boolean such asTrue
once the expression is evaluated. When you compare a numpy array with something likenumpyArray == list
, the result of that expression is another numpy array filled with booleans like this:[True, False, False]
. The tests aren't expecting this, and that's what causes the error.So, you need to not return a numpy array.
it becomes easy when u nderstand how to fill 2 dimentional array
In JavaScript, I ran into the following error when attempting to test:
"assertSimilar is deprecated, use assert.deepEqual"
Nice easy kata for matrix comprehension.
This comment has been hidden.
Should be fixed. Please verify.
RISC-V Translation
Approved
Python update (new testing framework)
approved.
Too easy, in comparison with other tasks of the 6 kyu. But the idea is really interesting, for learning to the use 2D arrays.
интересная задача, но легкая
Got me thinking for 10 minutes, good kata :)
Accomplished in c++. Kata seemed pretty hard, but I learn something about using 2d vectors.
How is this a kata issue?
F# translation kumited. Please review and approve. Thanks, suic
approved by
I really like this kata, it's simple, but fun. However, I can't accept this kata as a 6 kyu. Having just spent 30 minutes on a kata of the same difficulty (Banker's Plan), it just doesn't feel fair to give the same rating to one I spent 1 minute solving. Well, anyways, difficulty is arbitrary, and what matters is that I had fun.
In Julia this is a one liner. 7kyu would be a better choice.
One liner in C# too
oh such an awful habit of inserting "using namespace std;" in the global scope, please remove (c++)
This comment has been hidden.
I am not sure I understand the problem: all rows are of the same length, so the "rectangular" array seems a good fit? In a jagged array, you could have rows of different lengths, what does not make too much sense? If the table is always 10 rows long, and each row has 10 columns, then
int[10,10]
is better than an array of tenint[]
, each of potentially different length?Sorry, after reading my post it sure doesn't make any sense.
What I meant is that Linq in .NET only handles jagged arrays natively, and not multidimensional ones like here
You have to use extra tricks to use it (see https://stackoverflow.com/questions/18896150/c-sharp-linq-return-a-multidimensional-array-from-linq and the best answer's source)
This is why I'd argue that using jagged arrays as returned values would be better, as it's handled by Linq by default
What do you think ? Linq is why peopple use C# here in the first place. It's a bit of nitpicking though, I'll admit
Then I would say that this reasoning is backwards. Implementation should be driven by design, and not the other way round. Choosing an inferior interface only because it would allow you to use your favorite library is exactly reverse of how things should be done.
This is arguable. It would be also good to realize that Linq is just a tool and nothing else. It can be used where fit, and should not be used where it does not work.
@hobovsky: My 2 cents: It's not just LINQ. There aren't that many languages with multidimensional array support like C#. The original kata and all other translations expect a jagged array as output. IMO the translation is not consistent with the original (and the other translations) without a good reason.(*) The output format limits the possible ways to solve this kata or forces using some unusual tricks.
(*) When C# supports jagged arrays and jagged arrays are the usual way, what is the point of using a construct specific to C# which is not consistent with the original?
¯\_(ツ)_/¯
One option is to use C# to its fullest power and write a custom LINQ extension method that transforms any multidimensional array to a jagged one.
I just added a LINQ based one liner solution that is 2D array compliant, with no extra methods/extensions, but I do have the same musing about the choice to use a 2D array; multidim arrays are usually a pain in the ass compared to jagged.. I was expecting the output to be [][] rather than [,]..
Why don't you expetect lists of lists rather than Arrays???
If you're asking about a language where lists grow and arrays do not, perhaps it's because the size of these is known in advance..
Factor translation
Approved
Updated to Scala 3
.
Just a little annoying message in JS:
STDERR: assertSimilar is deprecated, use assertDeepEquals
Fixed in this fork
This comment has been hidden.
kata hint != kata suggestion
Thank you for this explanation, jeez, katas with ambigous explanations are terrible.
I liked this Kata. Hope to see more like it.
I think the problem is not well describes. Description is not clear enough.
COBOL translation
approved
Haskell translation: https://www.codewars.com/kumite/61b9cb3f6aac5e003f44beb3
Approved
NO random tests in CS least
All other languages have random tests, CS fixed here which is just a direct copy from JS with
chai
assertions (had to tweak down the input range to 50 to prevent buffer overflow still...) , closing ! ^^Python tests have nested
it
s which interfere with the test output.resolved by fork of someone
sorry but i don't understand what does "NxN" mean? If it's not difficult, give a link to the tutorial please
N = size
So if size is 3, you generate a table that's 3 numbers wide and 3 numbers tall (3x3). If size is 5, you generate one that's 5 wide and 5 tall (5x5).
thanks
It means n number of arrays, each containing n items.
Problem description is not clear. Can anyone please help by providing another example maybe?
Not an issue, the description is already very clear. If you still cannot get the grasp of it, maybe u can print the test cases in sample && random tests
Its just you have to create a matrix , if n is given, the matrix has to be of n * n.
Problem description is not so clear. Multipication table should be 1 2 2, 2 3 6, 3 6 18. If there is something else to achive should have more detail.
Were you able to figure out what exactly is the requirement of this question ?
Good kata, thank you!
Out of curiosty – is there possibly a way of doing not in quadratic time?
No! Actually you can write a code, running with linear time, but that time still would have to be n^2. And that's only if we had to return an 1D array instead of 2D array.
Well, I think it's a matter of perspective. With a size of n you always get n*n elements. To process all elements you are actually doing it in linear time (one operation per element). However since the result is always a quadratic amount of elements there is no way of doing it with n iterations. So it is sort of both.
This comment has been hidden.
This comment has been hidden.
Crystal translation kumited :) (author inactive for past two months)
This comment has been hidden.
OP solved it, closing
Why does it say "the test cases can no longer be edited" (Python)?
...
Github, "Time to release the 500 solves test edit limit?"
I'm not sure what the current rules are, but the thread sums up the reasoning behind why it was put in place.
Every user with "Edit locked test cases" privileges can modify them. The privilege is granted at 10,000 Honor.
If you need to edit tests but cannot do this, raise a suggestion or issue (if it's bug in tests). But check if it does not exist already somewhere below.
Thanks for the clarification!
This comment has been hidden.
https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#how-do-i-post-to-a-kata-discourse
Rust translation kumited! :-)
It includes random tests.
🖖
Getting an error in C
"Incorrect for multiplier 1 x 1 Expected 1 Received 1"
Not sure what I am missing...
I see that you have solved the kata, but can you reproduce the code that actually caused this error? This is very strange. Also, the message wouldn't look like that, it would read:
but I don't see how this would happen, so please show that code, thanks.
That is what it said, sorry about that.... was going off of memory switching to the discussion board. I'll see if I can recreate it. I honestly don't know. I was experimenting with the code and the way the logic flowed in my loops, I hard coded the n = 1 condition and forced array[0][0] = 1.
I will caveat that this was my first deep dive in dynamically allocating 2d arrays and working with double pointers. So there may have been issues within double pointer interations and how I was allocating memory for 2d arrays.
After much experimentation and reading about double pointers/dynamic allocation of 2d arrays I figured it out. Good Kata and pushed me into learning a new aspect of C.
Glad you enjoyed figured it out.. Awesome.
This comment has been hidden.
Julia translation
Approved
This comment has been hidden.
Kotlin translation awaiting review.
Seems you've forgot to add the error message in the sample tests.
Added.
I left it out intentionally as it didn't seem necessary with only one simple test, but if it's in there now that's fine too. 🖖
Go and C have tests with
0
as the input, while none of the other languages do, and the expected behavior is not defined.Go version fixed (i.e. tests with
0
were removed).Same now for C
TypeScript translation kumited. Please, review and approve. Thanks, suic
C++ Translation This is my first time writing C++ test case and any translation at all. Please review and feedback me if something is wrong.
Go translation kumited. Please review and approve. Regards, suic
Thanks for review and the approval! Regards, suic
Javascipt error doesn't say why?
Question not specified.
C translation kumited
please scrutinize for approval!
cheers!
python: function name should
camel_cased
Same for Ruby
This is the second time I see you mixing a
snake
with acamel
, :thinking:damn... x)
Both Ruby and Python fixed.
Groovy and Scala translation kumited. Please review and approve. Thanks, suic
JS :
(can't edit to fix)
@cliffstamp
: Please remember to resolve translation suggestions when you approve them. CheersFixed in this fork
Python and Ruby Translations :D
Could've included a few random test cases
Hello Bugari!
This gets marked as incorrect:
Expected: [[1,2,3],[2,4,6],[3,6,9]], instead got: [[1,2,3],[2,4,6],[3,6,9]]
And also:
Expected: [[1,2],[2,4]], instead got: [[1,2],[2,4]]
Do you need the code for feedback or do you have access to my kata because you're the creator? If you need it do I just post here?
Getting the exact same error even though all the various test cases I run are seemingly matching the expected.
Good one Bugari ! Had some difficults where to init my arrays but I found the solution ! :D
Error in typo: for given example, the return value should be: [[1,2,3],[2,4,8],[3,6,9]]
Should be: for given example, the return value should be: [[1,2,3],[2,4,6],[3,6,9]]
fixed... I feel like a retard :P
Row 2 of the example says 2 4 8. Should be 2 4 6
damn, that's right - fixed :)
Nice kata, @Bugari.
It would be awesome if you could log stuff out as an actual multiplication table; maybe using HTML tables and such to make it look like a real table.
But regardless, good job!
Hello. The only minor thing I noticed in the description is the example multiplication table is: 1 2 3 2 4 8 3 6 9 Row 2 should be "2 4 6". Good exercise! :)
damn, that's right - fixed :)