Image for post

Each day I solve several coding challenges and puzzles from Codr’s ranked mode. The goal is to reach genius rank, along the way I explain how I solve them. You do not need any programming background to get started, and you will learn a ton of new and interesting things as you go.

function swap(arr, [i, j], [m, n]) {
  const temp = arr[i][j];
  arr[i][j] = arr[m][n];
  arr[m][n] = temp;
}
function rotate(M) {
  const n = M.length;
  for (let i = 0; i < n-1; i++) {
    for (let j = 0; j < n-i; j++) {
      swap(M, [i, j], [n-j-1, n-i-1]);
    }
  }
  for (let i = 0; i < n/2; i++) {
    for (let j = 0; j < n; j++) {
      swap(M, [i, j], [n-i-1, j]);
    }
  }
}
let M = [
  [6,5,9],
  [8,1,5],
  [3,4,1]
]
rotate(M);
let A = M[2][1]
// A = ? (number)

#programming #computer-science #javascript #development #coding

Road to Genius: superior
1.45 GEEK