6 kyu

Matrix Division

Description:

When multiplying matrices, the elementij element_{ij} of the product matrix C is equal to the sum of pairwise products of the elements of rowirow_i of the left matrix A and elements of columnjcolumn_j of the right matrix B. For this kata, we will redefine matrix multiplication by removing the step with summation so that division of matrices can be unambiguously defined:

cij=(ai0b0j,ai1b1j,...,aikbkj)c_{ij} = (a_{i0} ∗ b_{0j}, a_{i1} ∗ b_{1j}, ..., a_{ik} ∗ b_{kj})

Task:

Implement a function matrix_div with 3 parameters:

  • result represents the product matrix C

  • factor represents one of the two factors (either A or B).

  • position is either 0 or 1: 0 means that given factor is the left factor while 1 means it's the right one.

Func should return the other factor.

Examples:

matrix_div([[[5, 14], [6, 16]], [[15, 28], [18, 32]]], [[1, 2], [3, 4]], 0) should return [[5, 6], [7, 8]]

matrix_div([[[5, 14], [6, 16]], [[15, 28], [18, 32]]], [[1, 2], [3, 4]], 1) should return [[5, 4], [15, 8]]

Constraints:

  • A[k×k],B[k×k]A[k×k], B[k×k] - for convenience

  • 1k301 ≤ k ≤ 30

  • Aij,BijZA_{ij}, B_{ij} ∈ Z

  • 1Aij,Bij1001 ≤ A_{ij}, B_{ij} ≤ 100

Matrix
Arrays

Similar Kata:

Stats:

CreatedJul 23, 2023
PublishedJul 23, 2023
Warriors Trained277
Total Skips112
Total Code Submissions147
Total Times Completed43
Python Completions43
Total Stars9
% of votes with a positive feedback rating92% of 24
Total "Very Satisfied" Votes21
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes1
Total Rank Assessments12
Average Assessed Rank
6 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Homogen Avatar
  • flodem Avatar
  • brodiemark Avatar
Ad