21
3
You're given a n-by-m matrix of integers, where n,m > 3. Your task is to find the 3-by-3 sub-matrix that has the lowest mean, and output this value.
Rules and clarifications:
- The integers will be non-negative
- Optional input and output format
- The output must be accurate up to at least 2 decimal poins (if it's non-integer)
- The submatrices must be made up of consecutive rows and columns
Test cases:
35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11
Minimum mean: 14
100 65 2 93
3 11 31 89
93 15 95 65
77 96 72 34
Minimum mean: 46.111
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
Minimum mean: 1
4 0 0 5 4
4 5 8 4 1
1 4 9 3 1
0 0 1 3 9
0 3 2 4 8
4 9 5 9 6
1 8 7 2 7
2 1 3 7 9
Minimum mean: 2.2222
This is code-golf so the shortest code in each language wins. I encourage people to post answers in languages that are already used, even if it's not shorter than the first one.
It would also be interesting to have a challenge with not necessarily contiguous rows and columns – Luis Mendo – 2017-02-04T14:18:15.250
No, go ahead yourself :-) – Luis Mendo – 2017-02-04T14:50:46.693
Do you mean integers in the mathematical or data type sense, i.e., can we take a matrix of integral floats? – Dennis – 2017-02-04T18:15:35.513
Mathematical sense. Is it one thing I've learned here, it is that you can make assumptions about data types in various languages... – Stewie Griffin – 2017-02-04T20:06:49.557
Sweet, that saves a byte. Thanks for clarifying. – Dennis – 2017-02-04T20:38:41.903
@Luis done. :-)
– Stewie Griffin – 2017-02-06T14:16:56.410@StewieGriffin Nice title! I'll give it a try later if I have some time – Luis Mendo – 2017-02-06T14:21:29.597