cube_solver.cube.utils module
Cube utils module.
- cube_solver.cube.utils.get_orientation_array(coord, v, n, force_modulo=False)[source]
Get orientation array.
Given an orientation coordinate number
coordwith a value between0andv ^ n - 1, wherevis the number of possible orientation values, returns a unique orientation array of lengthnwith values between0andv - 1for every possible orientation coordinate value.If
force_moduloisTrue, given an orientation coordinate number with a value between0andv ^ (n - 1) - 1, returns a unique orientation array with total orientation0 modulo v.- Parameters:
coord (int) – Orientation coordinate number with a value between
0andv ^ n - 1, or between0andv ^ (n - 1) - 1ifforce_moduloisTrue.v (int) – Number of possible orientation values.
n (int) – Length of the orientation array.
force_modulo (bool, optional) – If
True, returns a unique orientation array with total orientation0 modulo v. Default isFalse.
- Returns:
orientation – Orientation array of length
nwith values between0andv - 1.- Return type:
ndarray
Examples
>>> from cube_solver.cube.utils import get_orientation_array >>> get_orientation_array(6, 3, 3) array([0, 2, 0]) >>> get_orientation_array(6, 3, 3, force_modulo=True) array([2, 0, 1])
- cube_solver.cube.utils.get_orientation_coord(orientation, v, is_modulo=False)[source]
Get orientation coordinate number.
Given an
orientationarray of lengthnwith values between0andv - 1, wherevis the number of possible orientation values, returns a unique orientation coordinate number with a value between0andv ^ n - 1for every possible orientation array.If
is_moduloisTrue, given an orientation array with total orientation0 modulo v, returns a unique orientation coordinate number with a value between0andv ^ (n - 1) - 1.- Parameters:
orientation (ndarray) – Orientation array of length
nwith values between0andv - 1.v (int) – Number of possible orientation values.
is_modulo (bool, optional) – If
True, returns a unique orientation coordinate number for every possible orientation array with total orientation0 modulo v. Default isFalse.
- Returns:
coord – Orientation coordinate number with a value between
0andv ^ n - 1, or between0andv ^ (n - 1) - 1ifis_moduloisTrue.- Return type:
int
Examples
>>> import numpy as np >>> from cube_solver.cube.utils import get_orientation_coord >>> get_orientation_coord(np.array([0, 2, 0]), 3) 6 >>> get_orientation_coord(np.array([2, 0, 1]), 3, is_modulo=True) 6
- cube_solver.cube.utils.get_permutation_array(coord, n, force_even_parity=False)[source]
Get permutation array and permutation parity.
Given a permutation coordinate number
coordwith a value between0andn! - 1, returns a unique permutation array of lengthnwith values between0andn - 1for every possible permutation coordinate value. Also returns the permutation parity:Trueif the permutation array hasoddparity,Falseif it hasevenparity.If
force_even_parityisTrue, given a permutation coordinate number with a value between0andn! / 2 - 1, returns a unique permutation array withevenparity.- Parameters:
coord (int) – Permutation coordinate number with a value between
0andn! - 1, or between0andn! / 2 - 1ifforce_even_parityisTrue.n (int) – Length of the permutation array.
force_even_parity (bool, optional) – If
True, returns a unique permutation array withevenparity. Default isFalse.
- Returns:
permutation (ndarray) – Permutation array of length
nwith values between0andn - 1.parity (bool) – Permutation parity:
Trueif the permutation array hasoddparity,Falseif it hasevenparity.
- Return type:
Tuple[ndarray, bool]
Examples
>>> from cube_solver.cube.utils import get_permutation_array >>> get_permutation_array(2, 3) (array([1, 0, 2]), True) >>> get_permutation_array(2, 3, force_even_parity=True) (array([2, 0, 1]), False)
- cube_solver.cube.utils.get_permutation_coord(permutation, is_even_parity=False)[source]
Get permutation coordinate number.
Given a
permutationarray of lengthnwithndifferent values, returns a unique permutation coordinate number with a value between0andn! - 1for every possible permutation array.If
is_even_parityisTrue, given a permutation array withevenparity, returns a unique permutation coordinate number with a value between0andn! / 2 - 1.- Parameters:
permutation (ndarray) – Permutation array of length
nwithndifferent values.is_even_parity (bool, optional) – If
True, returns a unique permutation coordinate number for every possible permutation array withevenparity. Default isFalse.
- Returns:
coord – Permutation coordinate number with a value between
0andn! - 1, or between0andn! / 2 - 1ifis_even_parityisTrue.- Return type:
int
Examples
>>> import numpy as np >>> from cube_solver.cube.utils import get_permutation_coord >>> get_permutation_coord(np.array([1, 0, 2])) 2 >>> get_permutation_coord(np.array([2, 0, 1]), is_even_parity=True) 2
- cube_solver.cube.utils.get_permutation_parity(permutation)[source]
Get permutation parity.
Given a
permutationarray of lengthnwithndifferent values, returns the permutation parity:Trueif the permutation array hasoddparity,Falseif it hasevenparity.- Parameters:
permutation (ndarray) – Permutation array of length
nwithndifferent values.- Returns:
parity – Permutation parity:
Trueif the permutation array hasoddparity,Falseif it hasevenparity.- Return type:
bool
Examples
>>> import numpy as np >>> from cube_solver.cube.utils import get_permutation_parity >>> get_permutation_parity(np.array([1, 0, 2])) True >>> get_permutation_parity(np.array([2, 0, 1])) False
- cube_solver.cube.utils.get_combination_array(coord, n)[source]
Get combination array.
Given a combination coordinate number
coordwith a value between0andC(m, n) - 1, wherem - 1is the maximum value of the combination array andn <= m, returns a unique combination array of lengthnwith values in increasing order between0andm - 1for every possible combination coordinate value.- Parameters:
coord (int) – Combination coordinate number with a value between
0andC(m, n) - 1, wherem - 1is the maximum value of the combination array andn <= m.n (int) – Length of the combination array.
- Returns:
combination – Combination array of length
nwith values in increasing order between0andm - 1.- Return type:
ndarray
Examples
>>> from cube_solver.cube.utils import get_combination_array >>> get_combination_array(3, 2) array([0, 3]) >>> get_combination_array(6, 3) array([1, 2, 4])
- cube_solver.cube.utils.get_combination_coord(combination)[source]
Get combination coordinate number.
Given a
combinationarray of lengthnwith values in increasing order between0andm - 1, wherem - 1is the maximum value of the combination array andn <= m, returns a unique combination coordinate number with a value between0andC(m, n) - 1for every possible combination array.- Parameters:
combination (ndarray) – Combination array of length
nwith values in increasing order between0andm - 1.- Returns:
coord – Combination coordinate number with a value between
0andC(m, n) - 1, wherem - 1is the maximum value of the combination array andn <= m.- Return type:
int
Examples
>>> import numpy as np >>> from cube_solver.cube.utils import get_combination_coord >>> get_combination_coord(np.array([0, 3])) 3 >>> get_combination_coord(np.array([1, 2, 4])) 6
- cube_solver.cube.utils.get_partial_permutation_array(coord, n)[source]
Get permutation array and combination array.
Given a partial permutation coordinate number
coordwith a value between0andP(m, n) - 1, wherem - 1is the maximum value of the combination array andn <= m, returns a unique pair of a permutation array of lengthnwith values between0andn - 1, and a combination array of lengthnwith values in increasing order between0andm - 1, for every possible partial permutation coordinate value.- Parameters:
coord (int) – Partial permutation coordinate number with a value between
0andP(m, n) - 1, wherem - 1is the maximum value of the combination array andn <= m.n (int) – Length of the permutation array and the combination array.
- Returns:
permutation (ndarray) – Permutation array of length
nwith values between0andn - 1.combination (ndarray) – Combination array of length
nwith values in increasing order between0andm - 1.
- Return type:
Tuple[ndarray, ndarray]
Examples
>>> from cube_solver.cube.utils import get_partial_permutation_array >>> get_partial_permutation_array(6, 2) (array([0, 1]), array([0, 3])) >>> get_partial_permutation_array(38, 3) (array([1, 0, 2]), array([1, 2, 4]))
- cube_solver.cube.utils.get_partial_permutation_coord(permutation, combination)[source]
Ger partial permutation coordinate number.
Given a
permutationarray of lengthnwithndifferent values, and acombinationarray of lengthnwith values in increasing order between0andm - 1, wherem - 1is the maximum value of the combination array andn <= m, returns a unique partial permutation coordinate number with a value between0andP(m, n) - 1for every possible pair of permutation array and combination array.- Parameters:
permutation (ndarray) – Permutation array of length
nwithndifferent values.combination (ndarray) – Combination array of length
nwith values in increasing order between0andm - 1.
- Returns:
coord – Partial permutation coordinate number with a value between
0andP(m, n) - 1, wherem - 1is the maximum value of the combination array andn <= m.- Return type:
int
Examples
>>> import numpy as np >>> from cube_solver.cube.utils import get_partial_permutation_coord >>> get_partial_permutation_coord(np.array([0, 1]), np.array([0, 3])) 6 >>> get_partial_permutation_coord(np.array([1, 0, 2]), np.array([1, 2, 4])) 38