5 kyu

Square Matrix Multiplication

1,507 of 7,772xDranik
Description
Loading description...
Matrix
Linear Algebra
Algorithms
View
AllIssues12Questions1Suggestions7Show Resolved
  • Please sign in or sign up to leave a comment.
  • tobeannouncd Avatar

    This comment has been hidden.

  • ddx1 Avatar

    fundamentals ;-)

  • ishan mohan bishnoi Avatar

    Will the matrices go beyond 3x3 matrices??? or under 3x3 matrices please help???

  • MikChan Avatar

    C++ fork with some minor improvements:

    • Initial solution changed according to C++ authoring guidelines
    • Function signature is no longer enforced (required for backwards compatibility)
    • Moved the reference solution out of the global scope
    • Some minor code formatting adjustments

    Please, review and approve/reject

  • trashy_incel Avatar

    C:

    • the input matrices should be const-qualified
    • unhelpful assertion messages

    fixed here

  • Tasups Avatar

    This is JavaScript version Got this error:

    STDERR assertSimilar is deprecated, use assert.deepEqual

    Then I changed assertSimilar in the Sample Tests and got this:

    TypeError: Cannot read properties of undefined (reading 'deepEqual') at Context. (test.js:28:13) at process.processImmediate (node:internal/timers:471:21)

    Any advice? Is it something that I can fix on my end?

  • anthonyleestark Avatar

    C++ Error:

    Test Results: the_matrix_multiplication_function -> should_work_for_100_pairs_of_randomly_generated_matrices (FAILED)

  • AndrewMarsh Avatar

    I think that this kata is a bit too easy for 5 kyu.

  • germenix Avatar

    Traceback (most recent call last): File "/workspace/default/tests.py", line 3, in test.assert_equals(matrix_mult( File "/workspace/default/.venv/lib/python3.11/site-packages/codewars_test/test_framework.py", line 35, in assert_equals expect(actual == expected, message, allow_raise) File "/workspace/default/.venv/lib/python3.11/site-packages/codewars_test/test_framework.py", line 19, in expect if passed: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

  • omarbr44 Avatar

    My solution passed the test but in the attempt it gives me this message -> TypeError: Cannot set property '0' of undefined.WHAT is the problem??

  • <Merlin> Avatar

    That was fun! :D

  • memExpert Avatar

    I agree with Caydenz. My program goes through 300-2000 tests and one constantly returns an error. It would be nice if I could at least see the received and expected value so I know where to start. I am using dynamic memory allocation and do not modify the input matrices. (Decision in C. I'm sorry for my english).

    PS. The problem has been resolved. I advise you to use calloc instead of malloc.

  • Caydenz Avatar

    Something is wrong with C tests:

    Test Results: the_matrix_multiplication_function should_work_for_100_pairs_of_randomly_generated_matrices (449 of 450 Assertions) should_work_for_some_fixed_assertions (13 of 13 Assertions) should_work_for_the_example_provided_in_the_description (4 of 4 Assertions) Completed in 143.9431ms

    Last test in should_work_for_100_pairs_of_randomly_generated_matrices always fails.

  • polokojoko Avatar

    Hello. I've some questions. In C# we have two arrays like: int[,] a = { { 9, 7 }, { 0, 1 } }; int[,] b = { { 1, 1 }, { 4, 12 } };

    This is expected value: int[,] expected = { { 37, 93 }, { 4, 12 } };

    But how we reach this? My logic is: 9 * 0 + 9 * 4 = 28 9 * 1 + 7 * 12 = 93 1 * 0 + 1 * 4 = 4 1 * 1 + 1 * 12 = 13

    Where I got wrong?

  • Abdurauf  Avatar

    This comment has been hidden.

  • CrimpCity Avatar

    This is WAY too hard for 5 kyu. The numpy approach didn't work for me.

  • dlcoe Avatar

    C# errors are the name of the collection rather than the content.

    Test Failed
    Expected is <System.Int32[2,2]>, actual is <System.Int32[1,1]>

    While in there, it would be really nice if the tabs were standardized to 4 spaces.

  • Damo67 Avatar

    This problem is way to easy for a 5 kyu rating in C#.

  • KataSideKick Avatar

    C# Translation added.Please review and approve~

  • MarosVarchola Avatar

    This comment has been hidden.

  • MarosVarchola Avatar

    This comment has been hidden.

  • user6793616 Avatar

    For python this is hardly a kyu 7, let be kyu 5, unless imports are forbidden.

  • yellowBunny Avatar

    This comment has been hidden.

  • hobovsky Avatar

    Java translation - please review.

  • paulc Avatar

    Great kata!

  • anter69 Avatar

    The kata should not be restricted to square matrices.

  • anter69 Avatar

    Python translation kumited -- including random tests and a cleaner description. Please check and approve.

  • anter69 Avatar

    No random tests.

  • sam_knighthood Avatar

    C++ Translation Kumited - Based on C version, tests on larger matrices added.

  • quocnb Avatar

    I have a error when testing or attempt

    /workspace/setup.swift:6:13: error: use of unresolved identifier 'XCTAssertEqual'
                XCTAssertEqual(someInt, arr2[index] as! Int)
                ^~~~~~~~~~~~~~
    /workspace/setup.swift:8:13: error: use of unresolved identifier 'XCTAssertEqual'
                XCTAssertEqual(someIntArray, arr2[index] as! [Int])
                ^~~~~~~~~~~~~~
    /workspace/setup.swift:10:13: error: use of unresolved identifier 'XCTAssertEqual'
                XCTAssertEqual(someBool, arr2[index] as! Bool)
                ^~~~~~~~~~~~~~
    /workspace/setup.swift:12:13: error: use of unresolved identifier 'XCTAssertEqual'
                XCTAssertEqual(someDouble, arr2[index] as! Double)
                ^~~~~~~~~~~~~~
    /workspace/setup.swift:14:13: error: use of unresolved identifier 'XCTAssertEqual'
                XCTAssertEqual(someString, arr2[index] as! String)
                ^~~~~~~~~~~~~~
    /workspace/setup.swift:16:13: error: use of unresolved identifier 'XCTAssertTrue'
                XCTAssertTrue(val == nil && arr2[index] == nil)
                ^~~~~~~~~~~~~
    /workspace/setup.swift:18:13: error: use of unresolved identifier 'XCTFail'
                XCTFail("This data type is not handled in assertArraysOfAnyEqual")
                ^~~~~~~
    /runner/frameworks/swift/xctest/_XCTMain.swift:5:13: note: did you mean '_XCTMain'?
    public func _XCTMain(_ testCases: [XCTestCaseEntry]) -> Never {
    
  • donaldsebleung Avatar

    C Translation Kumited - please carefully review and approve :D

  • donaldsebleung Avatar

    The lack of assertions in the Submit Tests of the JavaScript version of this Kata is appalling.

  • jasonwyatt Avatar

    It seems like the test/setup scripts are broken.. I'm seeing these errors (unrelated to my code):

    /workspace/setup.swift:6:13: error: use of unresolved identifier 'XCTAssertEqual'
                XCTAssertEqual(someInt, arr2[index] as! Int)
                ^~~~~~~~~~~~~~
    /workspace/setup.swift:8:13: error: use of unresolved identifier 'XCTAssertEqual'
                XCTAssertEqual(someIntArray, arr2[index] as! [Int])
                ^~~~~~~~~~~~~~
    /workspace/setup.swift:10:13: error: use of unresolved identifier 'XCTAssertEqual'
                XCTAssertEqual(someBool, arr2[index] as! Bool)
                ^~~~~~~~~~~~~~
    /workspace/setup.swift:12:13: error: use of unresolved identifier 'XCTAssertEqual'
                XCTAssertEqual(someDouble, arr2[index] as! Double)
                ^~~~~~~~~~~~~~
    /workspace/setup.swift:14:13: error: use of unresolved identifier 'XCTAssertEqual'
                XCTAssertEqual(someString, arr2[index] as! String)
                ^~~~~~~~~~~~~~
    /workspace/setup.swift:16:13: error: use of unresolved identifier 'XCTAssertTrue'
                XCTAssertTrue(val == nil && arr2[index] == nil)
                ^~~~~~~~~~~~~
    /workspace/setup.swift:18:13: error: use of unresolved identifier 'XCTFail'
                XCTFail("This data type is not handled in assertArraysOfAnyEqual")
                ^~~~~~~
    /runner/frameworks/swift/xctest/_XCTMain.swift:5:13: note: did you mean '_XCTMain'?
    public func _XCTMain(_ testCases: [XCTestCaseEntry]) -> Never {
                ^
    
  • docgunthrop Avatar

    Here's a link to help people easily understand how matrix multiplication works: http://matrixmultiplication.xyz/

  • ecocode Avatar

    I found this really difficult but very enjoyable! upvoted

  • p4sh4 Avatar

    I think this kata needs a clarifications if matrices can be of different sizes.

  • maplealmond Avatar

    Ruby has a built in Matrix class. This problem is fun, but it also feels a bit pointless given that http://www.ruby-doc.org/stdlib-2.1.1/libdoc/matrix/rdoc/Matrix.html is in the standard library.

  • xDranik Avatar

    4 minor issues, but no comments saying what they are :/

  • lblackburn Avatar

    I'd suggest renaming the function matrix_mult (matrixMultiplication is not a conventional ruby function name)

    Also, it might be better to link the Wikipedia page on matrix multiplication than describe it in the markdown for the kata.

  • delfuego Avatar

    The pre-filled test case contains a compareMatrices function that's not defined in the test harness, so the pre-defined test won't run.

  • BattleRattle Avatar

    I would suggest to use Test.assertSimilar(expected, actual) in order to have a better feedback in case of wrong results.