1 Star 0 Fork 0

jimgo/Three Plus One Game

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tpo2n.mjs 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
/*
next maxtri
P
N → 0 3 1 4 2 5 6
0 0 0 3 3 1 1 6
1 0 0 3 3 1 1 6
2 0 0 3 3 1 1 6
3 4 4 2 2 5 5 2
4 4 4 2 2 5 5 2
5 4 4 2 2 5 5 2
6 - - - - - - 6
x a x c y b x b y a y c x b
\ / \ / \ / \ / \ / \ / \ /
0 1 2 3 4 5 6
/ \ / \ / \ / \ / \ / \ / \
a x b x c x a y b y c y b x
x b x b
3 <==> 6
a y b x
*/
export const NEXT_MAP = {
0: { 0: 0, 3: 0, 1: 3, 4: 3, 2: 1, 5: 1, 6: 6 },
1: { 0: 0, 3: 0, 1: 3, 4: 3, 2: 1, 5: 1, 6: 6 },
2: { 0: 0, 3: 0, 1: 3, 4: 3, 2: 1, 5: 1, 6: 6 },
3: { 0: 4, 3: 4, 1: 2, 4: 2, 2: 5, 5: 5, 6: 2 },
4: { 0: 4, 3: 4, 1: 2, 4: 2, 2: 5, 5: 5, 6: 2 },
5: { 0: 4, 3: 4, 1: 2, 4: 2, 2: 5, 5: 5, 6: 2 },
6: { 0: -1, 3: -1, 2: -1, 5: -1, 1: -1, 4: -1, 6: 6 },
};
/**
*
* @param {Number} p prev
* @param {Number} n next
* @returns next num after convertion
*/
export const nx = (p, n) => NEXT_MAP[p]?.[n] ?? -1;
export const next = (num) => {
let num1 = [0, ...num, 6];
let num2 = [];
for (let i = 0; i < num1.length - 1; i++) {
num2.push(nx(num1[i], num1[i + 1]))
}
// const num2 = num1.silce(0,-1).map((n, idx) => nx(n, n[idx + 1]));
while (num2[0] === 0) {
num2.shift();
}
while (num2[num2.length - 1] === 6) {
num2.pop();
}
return num2;
}
export const next2 = (num) => {
let num2 = next(num);
while (num2[num2.length - 1] === 0) {
num2.pop();
}
return num2;
}
const path = (num) => {
let num1 = Array.from(num);
while (true) {
if (num1.length <= 1) break;
console.log(num1.join(''));
num1 = next(num1);
}
}
const pathStr = (str) => path(str.split('').map(e => +e));
// test unit
const tuint = () => {
console.log(next([2, 4]));//"24->132"
console.log(next([1, 3, 2]));//"132->305"
console.log(next([3, 0, 3, 0, 2]));//"30302->4041"
path([2, 4]);
};
// tuint();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/jimgo/ThreePlusOneGame.git
git@gitee.com:jimgo/ThreePlusOneGame.git
jimgo
ThreePlusOneGame
Three Plus One Game
master

搜索帮助