18
0
Given a number n
, Output an ordered list of 1-based indices falling on either of the diagonals of an n*n
square matrix.
Example:
For an input of 3
:
The square shall be:
1 2 3
4 5 6
7 8 9
Now we select all the indices represented by \
, /
or X
(#
or non-diagonal positions are rejected)
\ # /
# X #
/ # \
The output shall be:
[1,3,5,7,9]
Test cases:
1=>[1]
2=>[1,2,3,4]
3=>[1,3,5,7,9]
4=>[1,4,6,7,10,11,13,16]
5=>[1,5,7,9,13,17,19,21,25]
There will be no accepted answer. I want to know the shortest code for each language.
1The question is asking for the (1-indexed) indices of the , / and X characters in the images. Not a bad question per se, but lacks explanation. – Arfie – 2017-08-24T09:24:01.623
If you are willing to provide a brief and clear explanation of what you want, We will probably reopen this, as it is not a bad challenge. As of now, it is just very unclear – Mr. Xcoder – 2017-08-24T09:36:58.197
I've voted to reopen, though you might also want to move the ascii images out of the examples area to avoid confusion. At first I wasn't sure if I had to produce those as well (but I understand the wanted output is only the list of indices) – Arfie – 2017-08-24T10:01:06.947
@Ruud: And how will do people understand what are the asked positions if they don't see the images? – sergiol – 2017-08-24T10:04:05.523
I'm not saying you shouldn't show them at all, just that you put them (or just two or three of them) with the explanation of the challenge, rather than the example inputs and outputs. – Arfie – 2017-08-24T10:05:10.523
7Does the order matter? – Mr. Xcoder – 2017-08-24T10:19:29.503
@sergiol Is 0-indexing allowed? My previous question stands ^ – Mr. Xcoder – 2017-08-24T10:58:39.620
@Mr.Xcoder: Does the order matter? Yes. Is 0-indexing allowed? No. Because it is how I specified the question in the examples. – sergiol – 2017-08-24T11:04:30.823
9FWIW I think having the order be irrelevant might make for more interesting golfs... – Jonathan Allan – 2017-08-24T11:17:11.577
Would a dash-separated string be a valid output? e.g.
"1-3-5-7-9"
– Arnauld – 2017-08-24T13:19:28.920@Arnauld: yes . – sergiol – 2017-08-24T13:20:26.140
@ThePirateBay: If you don't publish the derived challenge, I will publish it myself! – sergiol – 2017-08-25T11:09:25.860