Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 15469

This tag is for challenges involving matrices. A matrix, also known as a 2D array, is a list of numbers arranged in a rectangle with rows and columns.

1 vote

The Hungry Mouse

J, 82 bytes g=.](]*{:@[~:])]_1}~[:>./]{~((,-)1 5 6 7)+]i.{: [:+/[:(g^:_)16,~[:,0,~0,0,0,.~0,.] Try it online! I plan to golf this more tomorrow, and perhaps write a more J-ish solution similar to thi …
Jonah's user avatar
  • 33.8k
5 votes

Construct a Modulo Multiplication Table

J, 60 55 bytes 1}."1,/"2@((' ',.' ',":@,.){~(<|.)@(>/~)*1+#|>:*/>:)@i. Try it online! -5 thanks to xash I thought this would be a good challenge for J, and the essence of the problem is, but the form …
Jonah's user avatar
  • 33.8k
9 votes

Drop down the numbers

J, 24 20 bytes [:>./-@,|."0 2,*,=/] Try it online! -4 thanks to xash! Solved independently, but seems very similar to ovs's APL solution. This one works for any number, because I didn't notice that …
Jonah's user avatar
  • 33.8k
4 votes

Storing a band matrix

J, 66 53 bytes #{.#|.-@$(#"1~0{](]#~[-:"2*"2)#\>/#\|@-/#\)@|.]{.~3*$ Try it online! Basic Strategy We want to avoid special casing the "pad the partial top rows on the left", and "pad the partial bot …
Jonah's user avatar
  • 33.8k
3 votes

Checkered grid with X mark

J, 40 bytes ((2|+/~)@]+2**@[*=/~@]*(>:]*=/~))|@i:@<: Try it online!
Jonah's user avatar
  • 33.8k
3 votes

Make the cheapest cut

For example, if the input is a 3 x 4 matrix, the output will be length 5 and should be interpreted as follows: the first vertical cut is minimal v 0 0 | 1 0 0 ^^^ neither horizontal cut is …
Jonah's user avatar
  • 33.8k
3 votes

Find the box by its corners

The two parts that required the most experimentation to golf were: (;/-#:i.4)&{ The phrase to pull the 4 corners from a matrix. …
Jonah's user avatar
  • 33.8k
1 vote

Find the representative submatrix

J, 53 bytes <(0{]#~a:=-.&,&.>)[:(/:#@,@>)@,<<;._3&>~],@{@;&(#\)|: Try it online!
Jonah's user avatar
  • 33.8k
3 votes

Beware of the matrix tornado!

J, 37 bytes <./~@g`(|:@|.^:(1<@+>./@g=.#\.<.#\))} Try it online! Independently solved, but this approach is very similar to Lynn's. It is also one of the most perfect problems for J's little used "co …
Jonah's user avatar
  • 33.8k
0 votes

Matrix in Range

.@+:) NB. make the inner part of the matrix 1+i.@+: NB. 1..2*n, where n is the input (] [\ 1+i.@+:) NB. fork: infixes (sliding window …
Jonah's user avatar
  • 33.8k
3 votes

Reorder a matrix, twice

Main verb ]/:~"1/: The right most /: sorts the left arg (matrix) according to the order that would sort the right arg (specified order). This sorts rows. …
Jonah's user avatar
  • 33.8k
4 votes

In Flanders Fields

Multiplies by one minus the input, to get rid of endpoints (ie, original crosses) Add double the original matrix to that. …
Jonah's user avatar
  • 33.8k
5 votes

Dominate a zero-sum game

J, 43 41 40 39 bytes f=.(#~1=1#.]*/ .>:|:)@~. f&.:-&.|:@f^:_ Try it online! tldr how Create a function f to filter out dominated rows. Apply plain f, followed by f "under" a negative transpose, until …
Jonah's user avatar
  • 33.8k
2 votes

Output a Latin Square

Bash, 45 44 bytes for((i=0;i<$1*$1;)){ echo $[(i/$1+i++)%$1] } Try it online! -1 thanks to dingledooper Prints flattened square, one element per line.
Jonah's user avatar
  • 33.8k
2 votes

To raise \$ e \$ to the power of a matrix

J, 31 bytes [:+/!@i.@99%~]+/ .*^:(<99)[:=#\ Try it online! Just implements the formula up to 99 terms, which seems to be good enough to be within 1% of the test cases.
Jonah's user avatar
  • 33.8k

15 30 50 per page