Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let matrixSize = +gets();
- let matrix = Array.from(Array(matrixSize), () => new Array(matrixSize).fill(0));
- //col 0 1 2
- //row 0 - 1 6 7
- //row 1 - 2 5 8
- //row 2 - 3 4 9
- let num = 1;
- for(let coll = 0; coll < matrixSize; coll++){
- if(coll % 2 === 0){
- for(let row = 0; row < matrixSize; row++){
- matrix[row][coll] = num;
- num++
- }
- }else{
- for(let row = matrixSize-1; row >= 0; row--){
- matrix[row][coll] = num;
- num++
- }
- }
- }
- for(let coll = 0; coll < matrixSize; coll++){
- console.log(matrix[coll].join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement