georgiev955

09. Orbit

Jun 12th, 2023
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function orbit(input) {
  2.     let rows = Number(input[0]);
  3.     let cols = Number(input[1]);
  4.     let x = Number(input[2]);
  5.     let y = Number(input[3]);
  6.     let num = 1;
  7.     let matrix = new Array(rows).fill().map(() => new Array(cols).fill(0));
  8.     matrix[x][y] = num;
  9.     num++;
  10.    
  11.     for (let row = 0; row < rows; row++) {
  12.         for (let col = 0; col < cols; col++) {
  13.             matrix[row][col] = Math.max(Math.abs(row - x), Math.abs(col - y)) + 1;
  14.         }
  15.     }
  16.  
  17.     matrix.forEach(array => {
  18.         console.log(array.join(' '));
  19.     })
  20. }
Advertisement
Add Comment
Please, Sign In to add comment