upRightFrontToDownLeftFront method
Cube
upRightFrontToDownLeftFront(
- int index
)
Implementation
Cube upRightFrontToDownLeftFront(int index) {
final cp = List.filled(cornerCount, Corner.downRightBottom);
final corner = [
Corner.upRightFront, Corner.upFrontLeft, //
Corner.upLeftBottom, Corner.upBottomRight, //
Corner.downFrontRight, Corner.downLeftFront, //
];
final otherCorner = [
Corner.downBottomLeft,
Corner.downRightBottom,
];
var b = index % 720; // Permutation
var a = index ~/ 720; // Combination
// generate permutation from index b
for (var j = 1; j < 6; j++) {
var k = b % (j + 1);
b ~/= j + 1;
while (k-- > 0) {
_rotateRight(corner, 0, j);
}
}
var x = 5;
// generate combination and set edges
for (var j = Corner.downRightBottom.index; j >= 0; j--) {
if (a - _cnk(j, x + 1) >= 0) {
cp[j] = corner[x];
a -= _cnk(j, x-- + 1);
}
}
x = 0;
for (var j = Corner.upRightFront.index;
j <= Corner.downRightBottom.index;
j++) {
if (cp[j] == Corner.downRightBottom) {
cp[j] = otherCorner[x++];
}
}
return Cube._(cp: cp, co: _co, ep: _ep, eo: _eo);
}