【发布时间】:2021-11-10 17:07:25
【问题描述】:
我正在尝试将一些快速而肮脏的 javascript 代码放在一起,以在给定诸如“解决了 1 个边缘块”之类的约束条件下为我提供魔方上可能的块排列数量。 (为简单起见,坚持使用 3x3)当我通过我的函数运行正常的 12 个边缘和 8 个角时,它给了我一个比我能找到的答案大 4000 的数字。 (函数给我 43,252,003,274,489,860,000 但https://www.youtube.com/watch?v=z2-d0x_qxSM 说应该是 43,252,003,274,489,856,000)
我的代码:
// 3x3x3 Rubik's Cube
edgepieces = 12;
cornerpieces = 8;
centerpieces = 6;
// total possible permutations in general
function numCombos(edges, corners) {
result = ((factorial(edges) * (factorial(corners)) / 2) * (2 ** (edges - 1)) * (3 ** (corners - 1)));
return result;
}
// n!
function factorial(x) {
if (x == 0) {
return 1;
} else {
return x * factorial(x - 1);
}
}
console.log(numCombos(edgepieces, cornerpieces) + '\n');
我对核心结果算法遵循了几种不同的安排,它们都给了我这个最终结果。我错过了什么?
【问题讨论】: