Skip to content

Commit

Permalink
Merge pull request #3 from Morgan-Lee-Moran/main
Browse files Browse the repository at this point in the history
sort base on varity
  • Loading branch information
CmdBlockZQG authored May 22, 2024
2 parents 05d905b + f2274c6 commit 7e358fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ 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
2 changes: 1 addition & 1 deletion calc.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7e358fd

Please sign in to comment.