23
1
Given two positive numbers N >= 2
and N <= 100
create a matrix which follows the following rules:
- First Number starts at position
[0,0]
- Second Number starts at position
[0,1]
- Third number goes below First Number (position
[1,0]
) - Following numbers goes in "slash" direction
- Range of numbers used is
[1, N1 * N2]
. So, numbers goes from starting 1 to the result of the multiplication of both inputs.
Input
- Two numbers
N >= 2
andN <= 100
. First number is the amount of rows, Second number the amount of columns.
Output
- Matrix. (Can be outputted as a multidimensional array or a string with line breaks)
Example:
Given numbers 3 and 5
output:
1 2 4 7 10
3 5 8 11 13
6 9 12 14 15
Given numbers 2 and 2
1 2
3 4
Given Numbers 5 and 5
1 2 4 7 11
3 5 8 12 16
6 9 13 17 20
10 14 18 21 23
15 19 22 24 25
The shortest code in bytes wins.
Btw, is there a better name for this challenge? I dont know how to call it. – Luis felipe De jesus Munoz – 2018-04-24T12:34:31.067
2Can we use 0 indexing for any of the numbers? – Jo King – 2018-04-24T12:41:57.100
2@JoKing No. Must start at 1. – Luis felipe De jesus Munoz – 2018-04-24T12:42:58.473
5Very closely related. – AdmBorkBork – 2018-04-24T12:49:12.163
1@LuisfelipeDejesusMunoz Perhaps a better term for the order is "diagonals"? Personally, I'd call it a "zig-zag", because it reminds me of Cantor's Zig-Zag proof, but that might confusing. – mbomb007 – 2018-04-24T14:12:23.500
2@LuisfelipeDejesusMunoz anti-diagonal is the term for the other diagonal. – qwr – 2018-04-25T02:45:56.680