代码拉取完成,页面将自动刷新
/*
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();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。