Challenge: Linear Combination Checker

Write a Python algorithm to check if a matrix is an integer linear combination.

Problem statement

Write an IsIntLC function that accepts three matrices, A,BA, B, and CC as input. S={100,99,...1,0,1,...99,100}S=\{-100,-99,...-1,0,1,...99,100\} is the set of scalars to choose from. Your challenge is to check if matrix CC can be written as a linear combination of matrices AA and BB, with scalars from SS.

Example

Consider

A=[532678254]B=[111111111]andC=[643789365]A = \begin{bmatrix} 5 & 3 & 2\\ 6 & 7 & 8\\ 2 & 5 & 4 \end{bmatrix} \hspace{5mm} B = \begin{bmatrix} 1 & 1 & 1\\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{bmatrix} \hspace{5mm} \text{and} \hspace{5mm} C = \begin{bmatrix} 6 & 4 & 3\\ 7 & 8 & 9\\ 3 & 6 & 5 \end{bmatrix}

We can write CC as simply A+BA+B.

Sample input and output

The following table describes the expected input and output format.

Input Output
[[[5,3,2],[6,7,8],[2,5,4]],[[[5, 3, 2],[6, 7, 8],[2, 5, 4]],[[1,1,1],[1,1,1],[1,1,1]],[[1, 1, 1],[1, 1, 1],[1, 1, 1]],[[6,4,3],[7,8,9],[3,6,5]]][[6, 4, 3],[7, 8, 9],[3, 6, 5]]] True

Try it yourself

The function’s signature is given below:

Get hands-on with 1400+ tech skills courses.