frontRightToBottomRight method

Cube frontRightToBottomRight(
  1. int index
)

Implementation

Cube frontRightToBottomRight(int index) {
  final ep = List.filled(Edge.count, Edge.upRight);

  final sliceEdge = [
    Edge.frontRight, Edge.frontLeft, //
    Edge.bottomLeft, Edge.bottomRight
  ];

  final otherEdge = [
    Edge.upRight, Edge.upFront, //
    Edge.upLeft, Edge.upBottom, //
    Edge.downRight, Edge.downFront, //
    Edge.downLeft, Edge.downBottom, //
  ];

  var b = index % 24; // Permutation
  var a = index ~/ 24; // Combination
  var k = 0;

  // generate permutation from index b
  for (var j = 1; j < 4; j++) {
    k = b % (j + 1);
    b ~/= j + 1;

    while (k-- > 0) {
      _rotateRight(sliceEdge, 0, j);
    }
  }

  // generate combination and set slice edges
  var x = 3;

  for (var j = Edge.upRight.index; j <= Edge.bottomRight.index; j++) {
    if (a - _cnk(11 - j, x + 1) >= 0) {
      ep[j] = sliceEdge[3 - x];
      a -= _cnk(11 - j, x-- + 1);
    }
  }

  x = 0;

  // set the remaining edges UR..DB
  for (var j = Edge.upRight.index; j <= Edge.bottomRight.index; j++) {
    if (ep[j] == Edge.downBottom) {
      ep[j] = otherEdge[x++];
    }
  }

  return Cube._(cp: _cp, co: _co, ep: ep, eo: _eo);
}