Skip to main content
explanation
Source Link
ngn
  • 15.3k
  • 2
  • 43
  • 87

APL (Dyalog Classic), 2424 23 bytes

t∘↑¨(t¯1-1)↓(t←-t←2⍴⎕2⍴⎕)∘↑¨,\⍪⍀⍪¨⎕⍀⍪\⍪¨⎕

Try it online!Try it online!

the result is a matrix of matrices, though Dyalog's output formatting doesn't make that very obvious

input the matrix (), turn each element into a nested matrix onof its own (⍪¨), take prefix concatenations by row (,\) and by column (⍪⍀), input n (), take the bottom right n-by-n corner from each matrix ((-t←2⍴⎕)∘↑¨), drop the first n-1 rows and columns of nested matrices ((t¯1-1t←-2⍴⎕)↓), take the bottom right n-by-n corner from each matrix (t∘↑¨)

                                        ┌─┬──┬───┐
                                        │a│ab│abc│      ┼──┼───┤        ┼──┼───┤
 n=2       ┌─┬─┬─┐      ┌─┬──┬───┐      ├─┼──┼───┤      │ab│abc│        │ab│ bc│
┌───┐      │a│b│c│      │a│ab│bac│      │a│ab│abc│      │de│def│        │de│ ef│
│abc│  ⍪¨  ├─┼─┼─┤  ,\  ├─┼──┼───┤  ⍪⍀  │d│de│def│ 1 1↓ ┼──┼───┤¯2 ¯2∘↑¨┼──┼───┤
│def│ ---> │d│e│f│ ---> │d│de│edf│ ---> ├─┼──┼───┤ ---> │ab│abc│  --->  │  │   │
│ghi│      ├─┼─┼─┤      ├─┼──┼───┤      │a│ab│abc│      │de│def│        │de│ ef│
└───┘      │g│h│i│      │g│gh│hgi│      │d│de│def│      │gh│ghi│        │gh│ hi│
           └─┴─┴─┘      └─┴──┴───┘      │g│gh│ghi│      ┴──┴───┘        ┴──┴───┘
                                        └─┴──┴───┘

APL (Dyalog Classic), 24 bytes

(t-1)↓(-t←2⍴⎕)∘↑¨,\⍪⍀⍪¨⎕

Try it online!

the result is a matrix of matrices, though Dyalog's output formatting doesn't make that very obvious

input the matrix (), turn each element into a matrix on its own (⍪¨), take prefix concatenations by row (,\) and by column (⍪⍀), input n (), take the bottom right n-by-n corner from each matrix ((-t←2⍴⎕)∘↑¨), drop the first n-1 rows and columns of matrices ((t-1)↓)

APL (Dyalog Classic), 24 23 bytes

t∘↑¨(¯1-t←-2⍴⎕),⍀⍪\⍪¨⎕

Try it online!

the result is a matrix of matrices, though Dyalog's output formatting doesn't make that very obvious

input the matrix (), turn each element into a nested matrix of its own (⍪¨), take prefix concatenations by row (,\) and by column (⍪⍀), input n (), drop the first n-1 rows and columns of nested matrices ((¯1-t←-2⍴⎕)↓), take the bottom right n-by-n corner from each matrix (t∘↑¨)

                                        ┌─┬──┬───┐
                                        │a│ab│abc│      ┼──┼───┤        ┼──┼───┤
 n=2       ┌─┬─┬─┐      ┌─┬──┬───┐      ├─┼──┼───┤      │ab│abc│        │ab│ bc│
┌───┐      │a│b│c│      │a│ab│bac│      │a│ab│abc│      │de│def│        │de│ ef│
│abc│  ⍪¨  ├─┼─┼─┤  ,\  ├─┼──┼───┤  ⍪⍀  │d│de│def│ 1 1↓ ┼──┼───┤¯2 ¯2∘↑¨┼──┼───┤
│def│ ---> │d│e│f│ ---> │d│de│edf│ ---> ├─┼──┼───┤ ---> │ab│abc│  --->  │  │   │
│ghi│      ├─┼─┼─┤      ├─┼──┼───┤      │a│ab│abc│      │de│def│        │de│ ef│
└───┘      │g│h│i│      │g│gh│hgi│      │d│de│def│      │gh│ghi│        │gh│ hi│
           └─┴─┴─┘      └─┴──┴───┘      │g│gh│ghi│      ┴──┴───┘        ┴──┴───┘
                                        └─┴──┴───┘
added 285 characters in body
Source Link
ngn
  • 15.3k
  • 2
  • 43
  • 87

APL (Dyalog Classic), 24 bytes

(t-1)↓(-t←2⍴⎕)∘↑¨,\⍪⍀⍪¨⎕

Try it online!

the result is a matrix of matrices, though Dyalog's output formatting doesn't make that very obvious

input the matrix (), turn each element into a matrix on its own (⍪¨), take prefix concatenations by row (,\) and by column (⍪⍀), input n (), take the bottom right n-by-n corner from each matrix ((-t←2⍴⎕)∘↑¨), drop the first n-1 rows and columns of matrices ((t-1)↓)

APL (Dyalog Classic), 24 bytes

(t-1)↓(-t←2⍴⎕)∘↑¨,\⍪⍀⍪¨⎕

Try it online!

the result is a matrix of matrices, though Dyalog's output formatting doesn't make that very obvious

APL (Dyalog Classic), 24 bytes

(t-1)↓(-t←2⍴⎕)∘↑¨,\⍪⍀⍪¨⎕

Try it online!

the result is a matrix of matrices, though Dyalog's output formatting doesn't make that very obvious

input the matrix (), turn each element into a matrix on its own (⍪¨), take prefix concatenations by row (,\) and by column (⍪⍀), input n (), take the bottom right n-by-n corner from each matrix ((-t←2⍴⎕)∘↑¨), drop the first n-1 rows and columns of matrices ((t-1)↓)

Source Link
ngn
  • 15.3k
  • 2
  • 43
  • 87

APL (Dyalog Classic), 24 bytes

(t-1)↓(-t←2⍴⎕)∘↑¨,\⍪⍀⍪¨⎕

Try it online!

the result is a matrix of matrices, though Dyalog's output formatting doesn't make that very obvious