function kings_matrix(m) {
let A = [
[1, 1, 1],
[1, 0, 0],
[1, 0, 0]
];
let B = [
[1, 1],
[1, 0]
];
if (m == 1) {
return B;
} else if (m == 2) {
return A;
} else {
for (let i = 0; i < m - 2; i++) {
let C = assemble(A, B);
B = Object.assign([], A);
A = Object.assign([], C);
}
return A;
}
function assemble(A, B) {
let a = Object.assign([], A);
let b1 = Object.assign([], B);
let b2 = Object.assign([], B);
let an = A.length;
let bn = B.length;
let z1 = d3.range(an - bn).map(() => d3.range(bn).map(() => 0));
b1 = b1.concat(z1);
let z2 = d3.range(bn).map(() => d3.range(an - bn).map(() => 0));
b2 = d3.zip(b2, z2).map((aa) => aa.flat());
let z = d3.range(bn).map(() => d3.range(bn).map(() => 0));
let top = d3.zip(a, b1).map((aa) => aa.flat());
let bot = d3.zip(b2, z).map((aa) => aa.flat());
return top.concat(bot);
}
}