16
2
Definitions
The kth ring of a square matrix of size N, where 1 ≤ k ≤ ceiling(N/2) is the list formed by the elements of the kth and (N-k+1)th rows and columns, but without the first and last k-1 elements.
Example:
Matrix: 1 2 3 4 5 6 7 8 9 1 8 7 6 5 4 3 2 1 9 8 7 6 5 4 3 Delimited in rings: +-------------------+ | 1 2 3 4 5 | | +-----------+ | | 6 | 7 8 9 | 1 | | | +---+ | | | 8 | 7 | 6 | 5 | 4 | | | +---+ | | | 3 | 2 1 9 | 8 | | +-----------+ | | 7 6 5 4 3 | +-------------------+
The first ring of the above is 1,2,3,4,5,1,4,8,3,4,5,6,7,3,8,6
, the second is 7,8,9,5,9,1,2,7
and the third is 6
.
An N by N matrix of positive integers is (for the purposes of this challenge):
concave if all the integers on the kth ring are strictly greater than those on the (k+1)th ring, where k is any integer between 1 and N (those on the first ring are greater than those on the second, which are in turn greater than those on the third etc.). Example:
4 5 6 4 7 -> because 4,5,6,4,7,4,8,5,5,4,6,5,9,5,5,4 are all higher than 4 3 2 2 4 any of 3,2,2,3,2,3,3,2, which are all higher than 1 5 2 1 3 8 5 3 3 2 5 9 5 6 4 5
flat if all the integers in the matrix are equal. Another example (perhaps redundant):
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
convex if all the integers on the kth ring are strictly lower than those on the (k+1)th ring, where k is any integer between 1 and N (those on the first ring are lower than those on the second, which are in turn lower than those on the third etc.). Example:
1 2 1 -> because 1 and 2 are both lower than 6 2 6 2 1 2 1
mixed if the matrix doesn't satisfy any of the above criteria. Example:
3 3 3 3 3 3 2 2 2 3 3 2 3 2 3 3 2 2 2 3 3 3 3 3 3
Challenge
Given a square matrix of positive integers of size at least 3, classify it according to the definitions above. That is, output one of four different consistent values based on whether the matrix is concave, flat, convex or mixed.
You can compete in any programming language and can take input and provide output through any standard method and in any reasonable format, while taking note that these loopholes are forbidden by default. This is code-golf, so the shortest submission (in bytes) for every language wins.
Test cases
Here's a bunch of examples for you to choose from – I selected 6 from each category.
Concave
[[3, 3, 3], [3, 1, 3], [3, 3, 3]]
[[2, 3, 4], [5, 1, 6], [7, 8, 9]]
[[19, 34, 45], [34, 12, 14], [13, 13, 13]]
[[3, 4, 3, 4], [4, 2, 1, 3], [3, 1, 2, 4], [4, 3, 4, 3]]
[[4, 5, 6, 4, 7], [4, 3, 2, 2, 4], [5, 2, 1, 3, 8], [5, 3, 3, 2, 5], [9, 5, 6, 4, 5]]
[[7, 7, 7, 7, 7], [7, 6, 6, 6, 7], [7, 6, 5, 6, 7], [7, 6, 6, 6, 7], [7, 7, 7, 7, 7]]
Flat
[[1, 1, 1], [1, 1, 1], [1, 1, 1]]
[[2, 2, 2], [2, 2, 2], [2, 2, 2]]
[[8, 8, 8], [8, 8, 8], [8, 8, 8]]
[[120, 120, 120], [120, 120, 120], [120, 120, 120]]
[[10, 10, 10, 10], [10, 10, 10, 10], [10, 10, 10, 10], [10, 10, 10, 10]]
[[5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5]]
Convex
[[1, 2, 1], [2, 6, 2], [1, 2, 1]]
[[1, 1, 1], [1, 2, 1], [1, 1, 1]]
[[19, 34, 45], [34, 76, 14], [13, 6, 13]]
[[3, 3, 3, 3], [3, 4, 4, 3], [3, 4, 4, 3], [3, 3, 3, 3]]
[[192, 19, 8, 6], [48, 324, 434, 29], [56, 292, 334, 8], [3, 4, 23, 23]]
[[291, 48, 7, 5], [47, 324, 454, 30], [58, 292, 374, 4], [9, 2, 53, 291]]
Mixed
[[1, 2, 3], [4, 5, 9], [6, 7, 8]]
[[10, 14, 21], [100, 8, 3], [29, 2, 19]]
[[5, 5, 5, 5], [5, 4, 4, 5], [5, 4, 6, 5], [5, 5, 5, 5]]
[[3, 3, 3, 3], [3, 1, 2, 3], [3, 3, 2, 3], [3, 3, 3, 3]]
[[12, 14, 15, 16], [12, 18, 18, 16], [12, 11, 11, 16], [12, 14, 15, 16]]
[[5, 5, 5, 5, 5], [5, 4, 4, 4, 5], [5, 4, 6, 4, 5], [5, 4, 4, 4, 5], [5, 5, 5, 5, 5]]
This challenge has previously been posted in the Sandbox. Thanks to those who have given valuable feedback there.
– Mr. Xcoder – 2018-06-01T17:32:29.6202Boy, wouldn't it be nice to have some array-of-array string conversion to/from matrix functions handy to process all those test cases in a variety of languages :) – ngm – 2018-06-01T17:47:16.287
@ngm Don't you dare think we don't have one already! :P
– Mr. Xcoder – 2018-06-01T18:02:33.477