4
Given dimensions of a 2D array, except 1xn, that results in an odd number of elements, find the midpoint index.
Example: Input is 3x5, representing the 2D array
[0,0] [0,1] [0,2] [0,3] [0,4]
[1,0] [1,1] [1,2] [1,3] [1,4]
[2,0] [2,1] [2,2] [2,3] [2,4]
The midpoint index is [1,2]
Input
3
5
Output
1 , 2
Rules
- Standard code-golf rules, fewest bytes wins
- Either full program or function is permitted
- When input is either 1xn or the corresponding array would have an even number of elements, output must be [0,0]
- nx1 should be treated like any other array
6Most challenges on PPCG try to avoid special cases or error cases, instead guaranteeing that the input will be valid. It's your call to make, but I find that error handling is usually boilerplate that makes solutions longer without making them more interesting. – Esolanging Fruit – 2018-07-04T09:01:09.757
2
We have a Sandbox for Proposed Challenges.
– user202729 – 2018-07-04T09:07:15.737@EsolangingFruit The challenge here is to handle the invalid inputs, otherwise it would trivially be ⁽ⁿ⁻²⁾⁄₂. – Adám – 2018-07-04T09:24:08.167
5@Adám A challenge where the entire point is to detect and handle invalid inputs doesn't seem like a very interesting challenge to me. – Esolanging Fruit – 2018-07-04T09:29:22.570
4@EsolangingFruit There's nothing inherently wrong with challenges that a specific user happens to find uninteresting. Personally, I think having to catch such specific cases makes for some interesting golfing material. – Adám – 2018-07-04T09:31:28.377
1
@NoirAntares I've edited your challenge to make it unambiguous. Feel free to edit or roll back If my rewording does not match your intentions.
– Adám – 2018-07-04T09:33:01.970@JoKing Well, [⁽ⁿ⁻²⁾⁄₂,0], yeah. – Adám – 2018-07-04T09:50:21.517
3
output must be [0,0]
any reason behind that? How does that part add anything to computing the midpoint? Obviously, 1xn arrays or arrays with an even dimension don't have[0,0]
as their midpoints. – JungHwan Min – 2018-07-04T13:57:04.100