Skip to content

Commit

Permalink
Use maximum amount of fragment 8 and minimum amount of fragment 9
Browse files Browse the repository at this point in the history
  • Loading branch information
llc0930 committed Jun 19, 2024
1 parent e5dd341 commit 97aad85
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 18 deletions.
15 changes: 0 additions & 15 deletions calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,6 @@ function Solve(arr, num) {

dfs(0);

// Sort res by the number of distinct elements in each matrix, in descending order
// If the number of distinct elements is the same, sort by the highest number in l for each element used in A and B
res.sort((A, B) => {
let distinctA = new Set(A.flat()).size;
let distinctB = new Set(B.flat()).size;

if (distinctA !== distinctB) {
return distinctB - distinctA;
} else {
let maxA = Math.max(...A.flat().map(x => l[x-1]));
let maxB = Math.max(...B.flat().map(x => l[x-1]));
return maxB - maxA;
}
});

return res;
}

Expand Down
65 changes: 62 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
row: 5,
col: 6,
board: [],
num: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
num: new Array(11).fill(0),
res: false,
now: 0,
color: ['white', '#75C0FF', '#3B66CF', '#78ACC5', '#C8FAFD', '#FDFF00', '#4BFF00', '#FF9800', '#B9B24B', '#FF00AE', '#8A2BE2', '#FF00FF']
Expand All @@ -76,7 +76,66 @@
}
},
calc() {
this.res = Solve(this.board, this.num)
const num_8 = new Array(11).fill(0)
num_8[7] = Number(this.num[7])
num_8[8] = Number(this.row) * Number(this.col)
const num_n8 = this.num.map(el => el)
num_n8[7] = 0

const board_8 = Solve(this.board, num_8)
let mapped = board_8.map((el, i) => {
return { index: i, value: (el.flat().filter(el => el === 8).length / 5) }
})
mapped.sort((a, b) => b.value - a.value)

let sorted = []
let tmp = []
let c_8 = mapped[0].value
while (c_8 >= 0) {
sorted = mapped.filter(el => el.value === c_8).map(el => board_8[el.index])
for (let s = 0; s < sorted.length ; ++s) {
for (let r = 0; r < Number(this.row); ++r) {
sorted[s][r].forEach((el, i, arr) => {
if (arr[i] === 9) arr[i] = -1
})
}
for (let c_9 = 0; c_9 <= Number(this.num[8]); ++c_9) {
num_n8[8] = c_9
tmp = tmp.concat(Solve(sorted[s], num_n8))
if (tmp.length > 0) break
}
}
if (tmp.length > 0) break
--c_8
}

// Sort res by the number of distinct elements in each matrix, in descending order
// If the number of distinct elements is the same,
// sort by the highest number in l for each element used in A and B
tmp.sort((A, B) => {
let distinctA = new Set(A.flat()).size
let distinctB = new Set(B.flat()).size

if (distinctA !== distinctB) {
return distinctB - distinctA
} else {
let maxA = Math.max(...A.flat().map(x => this.num[x-1]))
let maxB = Math.max(...B.flat().map(x => this.num[x-1]))
return maxB - maxA
}
})

//let c_nAB = 0
tmp.sort((a, b) => {
return (a.flat().filter(el => el === 10).length / 2 + a.flat().filter(el => el === 11).length / 3) - (b.flat().filter(el => el === 10).length / 2 + b.flat().filter(el => el === 11).length / 3)
})
tmp.sort((a, b) => a.flat().filter(el => el === 9).length - b.flat().filter(el => el === 9).length)
/*tmp.forEach((el, i, arr) => {
if ( !(el.flat().includes(10)) && !(el.flat().includes(11)) ) ++c_nAB
})*/
//console.log(c_nAB)

this.res = tmp
this.now = 0
}
},
Expand All @@ -102,4 +161,4 @@
</style>
</body>

</html>
</html>

0 comments on commit 97aad85

Please sign in to comment.