-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolver.py
61 lines (54 loc) · 1.55 KB
/
solver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from rubikscubennnsolver.RubiksCube222 import RubiksCube222
from rubikscubennnsolver.RubiksCube333 import RubiksCube333
from rubikscubennnsolver.RubiksCube444 import RubiksCube444
from rubikscubennnsolver.RubiksCube555 import RubiksCube555
import logging
from math import sqrt
def solve_cube_from_string(inp_str: str, order: str = "URFDLB"):
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(filename)25s:%(lineno)d %(levelname)8s: %(message)s",
)
# Replace colors with readable letters by our solver
inp_str = (
inp_str.replace("G", "F").replace("Y", "D").replace("O", "L").replace("W", "U")
)
# Get Size of cube
size = int(sqrt((len(inp_str) / 6)))
# Currently Implemented Cubes
if size == 2:
cube = RubiksCube222(
inp_str,
order,
None
)
if size == 3:
cube = RubiksCube333(
inp_str,
order,
None
)
if size == 4:
cube = RubiksCube444(
inp_str,
order,
None,
)
if size == 5:
cube = RubiksCube555(
inp_str,
order,
None,
)
# Output the current cube
cube.print_cube("Initial Cube")
cube.sanity_check()
cube.solve([])
solution = [x for x in cube.solution if "COMMENT" not in x]
print(len(solution))
print(solution)
return solution
if __name__ == "__main__":
solve_cube_from_string(
"UUURRRUUUULUUDRLRUULRULFFURDDFDFLLRLFLRUBFFRURBUUUFRRD"
)