<script>
const SIZE = 10;
let X = [ 2, 1, -1, -2, -2, -1, 1, 2 ];
let Y = [ 1, 2, 2, 1, -1, -2, -2, -1 ];
function
getCountRec(board,i,j,n)
{
if
(n == 0)
return
;
for
(let k = 0; k < 8; k++) {
let p = i + X[k];
let q = j + Y[k];
if
(p >= 0 && q >= 0
&& p < 10 && q < SIZE) {
board[p][q] =
true
;
getCountRec(board, p, q, n - 1);
}
}
}
function
getCount(i, j, n)
{
let board =
new
Array(SIZE).fill(0).map(()=>
new
Array(N));
board[i][j] =
true
;
getCountRec(board, i, j, n);
let cnt = 0;
for
(let row of board) {
for
(let cell of row) {
if
(cell)
cnt++;
}
}
return
cnt;
}
let i = 3, j = 3,N = 2;
document.write(getCount(i, j, N),
"</br>"
);
</script>
const SIZE = 10;
let X = [ 2, 1, -1, -2, -2, -1, 1, 2 ];
let Y = [ 1, 2, 2, 1, -1, -2, -2, -1 ];
function
getCountRec(board,i,j,n)
{
if
(n == 0)
return
;
for
(let k = 0; k < 8; k++) {
let p = i + X[k];
let q = j + Y[k];
if
(p >= 0 && q >= 0
&& p < 10 && q < SIZE) {
board[p][q] =
true
;
getCountRec(board, p, q, n - 1);
}
}
}
function
getCount(i, j, n)
{
let board =
new
Array(SIZE).fill(0).map(()=>
new
Array(N));
board[i][j] =
true
;
getCountRec(board, i, j, n);
let cnt = 0;
for
(let row of board) {
for
(let cell of row) {
if
(cell)
cnt++;
}
}
return
cnt;
}
let i = 3, j = 3,N = 2;
document.write(getCount(i, j, N),
"</br>"
);
</script>