1 Star 0 Fork 0

jimgo/Three Plus One Game

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
3n+1 machine in byte org 4th compress.js 2.33 KB
一键复制 编辑 原始数据 按行查看 历史
/**
matrix
0 1 2 3 4 5 6 7
0 0 0 1 5 0 4 5 5
1 2 2 3 7 2 6 7 7
2 2 2 3 7 2 6 7 7
3 0 0 1 5 0 4 5 5
4 2 2 3 7 2 6 7 7
5 0 0 1 5 0 4 5 5
6 0 0 1 5 0 4 5 5
7 2 2 3 7 2 6 7 7
Optimization:
0 1 4 3 6 7 2 5
0 0 0 0 5 5 5 1 4
5 0 0 0 5 5 5 1 4
3 0 0 0 5 5 5 1 4
6 0 0 0 5 5 5 1 4
1 2 2 2 7 7 7 3 6
2 2 2 2 7 7 7 3 6
4 2 2 2 7 7 7 3 6
7 2 2 2 7 7 7 3 6
Because:
1,4 3,6
1 0 1 0
0 0 1 1
0 1 0 1
Use:
4 => 1,
6 => 3,
7 => 4,
Compress:
0 1 3 4 2 5
0 0 0 5 5 1 1
3 0 0 5 5 1 1
5 0 0 5 5 1 1
1 2 2 4 4 3 3
2 2 2 4 4 3 3
4 2 2 4 4 3 3
Swap:
1 <=> 3,
2 <=> 5,
Order:
0 3 1 4 2 5
0 0 0 2 2 3 3
1 0 0 2 2 3 3
2 0 0 2 2 3 3
3 5 5 4 4 1 1
4 5 5 4 4 1 1
5 5 5 4 4 1 1
*/
const matrix = [
[0, 0, 1, 5, 0, 4, 5, 5],
[2, 2, 3, 7, 2, 6, 7, 7],
[2, 2, 3, 7, 2, 6, 7, 7],
[0, 0, 1, 5, 0, 4, 5, 5],
[2, 2, 3, 7, 2, 6, 7, 7],
[0, 0, 1, 5, 0, 4, 5, 5],
[0, 0, 1, 5, 0, 4, 5, 5],
[2, 2, 3, 7, 2, 6, 7, 7],
];
Object.defineProperty(matrix, "debug", {
get: function () {
let str = "\n 0 1 2 3 4 5 6 7\n";
for (let i = 0; i < this.length; i++) {
str += `${i} ${this[i].join(" ")}\n`;
}
return str;
},
});
/**
* => A,B <=
* I. matrix[X][A] === matrix[X][B]
* II. matrix[A][X] === matrix[B][X]
*/
for (let A = 0; A < 8; A++) {
for (let B = A + 1; B < 8; B++) {
OUTER: {
for (let i = 0; i < 8; i++) {
if (matrix[i][A] !== matrix[i][B]) break OUTER;
if (matrix[A][i] !== matrix[B][i]) break OUTER;
}
console.log(`Match A: ${A},B: ${B}`);
}
}}
/**
* Know that Pairs are [1,4] and [3,6]
* Now make the matrix more like Older Version.
*/
const compressed = `
0 1 3 4 2 5
0 0 0 5 5 1 1
3 0 0 5 5 1 1
5 0 0 5 5 1 1
1 2 2 4 4 3 3
2 2 2 4 4 3 3
4 2 2 4 4 3 3
`
const compressArray = Array.from(compressed);
for (let i = 0; i < compressArray.length; i++) {
if(compressArray[i] === '1') compressArray[i] = '3';
else if(compressArray[i] === '3') compressArray[i] = '1';
else if(compressArray[i] === '2') compressArray[i] = '5';
else if(compressArray[i] === '5') compressArray[i] = '2';
}
console.log("Is Old Version ? \n",compressArray.join(""));
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/jimgo/ThreePlusOneGame.git
git@gitee.com:jimgo/ThreePlusOneGame.git
jimgo
ThreePlusOneGame
Three Plus One Game
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385