var scriptTag = document.querySelector('#maxoptra-widget-script,#tracking-widget-script');
scriptTag.parentNode.insertBefore(frame, scriptTag.nextSibling);
code { white-space: pre-line; }
, тогда переносы останутся, все отступы исчезнут, а пробелы сократятся до одного.const tiles = [
[1, 0, 7, 5],
[3, 4, 1, 3],
[5, 1, 1, 4],
[7, 6, 1, 8],
[5, 7, 4, 4],
[8, 3, 3, 4],
[7, 1, 5, 4],
[4, 1, 1, 0],
[3, 1, 1, 4],
[2, 4, 3, 8],
[5, 1, 1, 7],
[4, 2, 4, 2],
];
function calculateLimits(field, tileNumber) {
switch (tileNumber) {
case 0:
return [
[0, 9],
[0, 9],
[0, 9],
];
case 1:
return [
[0, 10 - field[0][1]],
[0, 9],
[0, 9],
];
case 2:
return [
[0, 9],
[0, 10 - field[0][2]],
[0, 9],
];
case 3:
return [
[0, 10 - field[0][2] - field[2][1]],
[0, 10 - field[0][3] - field[1][2]],
[0, 10 - field[2][3]],
];
case 4:
return [
[
10 - field[0][3] - field[1][2] - field[3][1],
10 - field[0][3] - field[1][2] - field[3][1],
],
[0, 10 - field[1][3]],
[0, 10 - field[3][3]],
];
case 5:
return [
[0, 10 - field[1][3] - field[4][1]],
[0, 9],
[0, 10 - field[4][3]],
];
case 6:
return [
[0, 10 - field[2][2]],
[0, 10 - field[2][3] - field[3][2]],
[0, 9],
];
case 7:
return [
[
10 - field[2][3] - field[3][2] - field[6][1],
10 - field[2][3] - field[3][2] - field[6][1],
],
[0, 10 - field[3][3] - field[4][2]],
[0, 10 - field[6][3]],
];
case 8:
return [
[
10 - field[3][3] - field[4][2] - field[7][1],
10 - field[3][3] - field[4][2] - field[7][1],
],
[0, 10 - field[4][3] - field[5][2]],
[0, 10 - field[7][3]],
];
case 9:
return [
[
10 - field[4][3] - field[5][2] - field[8][1],
10 - field[4][3] - field[5][2] - field[8][1],
],
[0, 10 - field[5][3]],
[0, 10 - field[8][3]],
];
case 10:
return [
[0, 10 - field[6][3] - field[7][2]],
[0, 10 - field[7][3] - field[8][2]],
[0, 9],
];
case 11:
return [
[
10 - field[7][3] - field[8][2] - field[10][1],
10 - field[7][3] - field[8][2] - field[10][1],
],
[0, 10 - field[8][3] - field[9][2]],
[0, 10 - field[10][3]],
];
}
}
function nextTile(field, restTiles, tileNumber) {
if (tileNumber === 12) {
return [field];
}
const limits = calculateLimits(field, tileNumber);
let results = [];
for (let i = 0; i < restTiles.length; i += 1) {
if (
restTiles[i][0] >= limits[0][0] && restTiles[i][0] <= limits[0][1] &&
restTiles[i][1] >= limits[1][0] && restTiles[i][1] <= limits[1][1] &&
restTiles[i][2] >= limits[2][0] && restTiles[i][2] <= limits[2][1]
) {
const newTiles = restTiles.concat([]);
newTiles.splice(i, 1);
results = results.concat(
nextTile(field.concat([restTiles[i]]), newTiles, tileNumber + 1),
);
}
}
return results;
}
const result = nextTile([], tiles, 0);
for (let i = 0; i < result.length; i += 1) {
for (let j = 0; j < 12; j += 1) {
console.log(result[i][j].join(' '));
}
console.log('');
}
/*
5 7 4 4
3 4 1 3
8 3 3 4
3 1 1 4
4 2 4 2
5 1 1 4
7 1 5 4
4 1 1 0
1 0 7 5
7 6 1 8
5 1 1 7
2 4 3 8
*/
for (int first = 0; first < 12; first++) {
for (int second = 0; second < 12; second++) {
if (second == first) {
continue;
}
for (int third = 0; third < 12; third++) {
if (third == second || third == first) {
continue;
}
for (int fourth = 0; fourth < 12; fourth++) {
if (fourth == third || fourth == second || fourth == first) {
continue;
}
if (DoSquaresFitToGreenCondition(squares[first], squares[second], squares[third], squares[fourth])) {
greenSquares.Add(new List<int> { first, second, third, fourth });
}
}
}
}
}
static bool DoSquaresFitToGreenCondition(List<int> fisrt, List<int> second, List<int> third, List<int> fourth)
{
int sumCenter = fisrt[3] + second[2] + third[1] + fourth[0];
int sumTop = first[1] + second[0];
int sumBottom = third[3] + fourth[2];
int sumLeft = first[2] + third[0];
int sumRight = second[3] + fourth[1];
return sumCenter == 10 && sumTop <= 10 && sumBottom <= 10 && sumLeft <= 10 && sumRight <= 10;
}