11
1
Related, but very different.
In the examples below, A
and B
will be 2-by-2 matrices, and the matrices are one-indexed.
A Kronecker product has the following properties:
A⊗B = A(1,1)*B A(1,2)*B
A(2,1)*B A(2,2)*B
= A(1,1)*B(1,1) A(1,1)*B(1,2) A(1,2)*B(1,1) A(1,2)*B(1,2)
A(1,1)*B(2,1) A(1,1)*B(2,2) A(1,2)*B(2,1) A(1,2)*B(2,2)
A(2,1)*B(1,1) A(2,1)*B(1,2) A(2,2)*B(1,1) A(2,2)*B(1,2)
A(2,2)*B(2,1) A(2,2)*B(1,2) A(2,2)*B(2,1) A(2,2)*B(2,2)
Challenge: Given two matrices, A
and B
, return A⊗B
.
- The size of the matrices will be at least
1-by-1
. The maximum size will be whatever your computer / language can handle by default, but minimum5-by-5
input. - All input values will be non-negative integers
- Builtin functions that calculate Kronecker products or Tensor/Outer products are not allowed
- In general: Standard rules regarding I/O format, program & functions, loopholes etc.
Test cases:
A =
1 2
3 4
B =
5 6
7 8
A⊗B =
5 6 10 12
7 8 14 16
15 18 20 24
21 24 28 32
B⊗A =
5 10 6 12
15 20 18 24
7 14 8 16
21 28 24 32
------------------------
A =
1
2
B =
1 2
A⊗B =
1 2
2 4
------------------------
A =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
B =
1 1
0 1
A⊗B =
16 16 2 2 3 3 13 13
0 16 0 2 0 3 0 13
5 5 11 11 10 10 8 8
0 5 0 11 0 10 0 8
9 9 7 7 6 6 12 12
0 9 0 7 0 6 0 12
4 4 14 14 15 15 1 1
0 4 0 14 0 15 0 1
B⊗A =
16 2 3 13 16 2 3 13
5 11 10 8 5 11 10 8
9 7 6 12 9 7 6 12
4 14 15 1 4 14 15 1
0 0 0 0 16 2 3 13
0 0 0 0 5 11 10 8
0 0 0 0 9 7 6 12
0 0 0 0 4 14 15 1
------------------------
A = 2
B = 5
A⊗B = 10
1Or, in IPA, /y/ – Luis Mendo – 2016-04-28T13:42:06.033
Not every person knows IPA. – Leaky Nun – 2016-04-28T13:42:49.873
4Thanks for the explanation of how to pronounce Martin's last name. It's super relevant. :P – Alex A. – 2016-04-28T15:08:39.250
Well it's how I show respect... – Leaky Nun – 2016-04-28T15:09:22.920
;/
can beẎ
now. (feature postdates challenge?) – user202729 – 2018-03-25T02:27:28.347