pglass / cube Goto Github PK
View Code? Open in Web Editor NEWPython Rubik's cube solver
License: MIT License
Python Rubik's cube solver
License: MIT License
First and foremost, great job! I have a question about the solver. I might be missing something here, or I could be using it incorrectly. In the example below, I input an already solved cube. My confusion is why the solver is generating a solving sequence for a cube that's already solved. Shouldn't the solver's "moves" array be empty in such a case?
Code:
c = Cube("OOOOOOOOOYYYWWWGGGBBBYYYWWWGGGBBBYYYWWWGGGBBBRRRRRRRRR")
print(c)
print(c.is_solved())
solver = Solver(c)
solver.solve()
print(solver.moves)
Output:
OOO
OOO
OOO
YYY WWW GGG BBB
YYY WWW GGG BBB
YYY WWW GGG BBB
RRR
RRR
RRR
True
['Z', 'Zi', 'D', 'B', 'Di', 'B', 'B', 'B', 'B', 'D', 'Bi', 'Di', 'Z', 'D', 'B', 'Di', 'B', 'B', 'B', 'B', 'D', 'Bi', 'Di', 'Z', 'D', 'B', 'Di', 'B', 'B', 'B', 'B', 'D', 'Bi', 'Di', 'Z', 'D', 'B', 'Di', 'B', 'B', 'B', 'B', 'D', 'Bi', 'Di', 'Z', 'B', 'L', 'Bi', 'Li', 'Bi', 'Di', 'B', 'D', 'B', 'Bi', 'Di', 'B', 'D', 'B', 'L', 'Bi', 'Li', 'Z', 'B', 'L', 'Bi', 'Li', 'Bi', 'Di', 'B', 'D', 'B', 'Bi', 'Di', 'B', 'D', 'B', 'L', 'Bi', 'Li', 'Z', 'B', 'L', 'Bi', 'Li', 'Bi', 'Di', 'B', 'D', 'B', 'Bi', 'Di', 'B', 'D', 'B', 'L', 'Bi', 'Li', 'Z', 'B', 'L', 'Bi', 'Li', 'Bi', 'Di', 'B', 'D', 'B', 'Bi', 'Di', 'B', 'D', 'B', 'L', 'Bi', 'Li', 'Z', 'X', 'X', 'D', 'F', 'R', 'Fi', 'Ri', 'Di', 'Xi', 'Xi', 'X', 'X', 'Zi', 'Li', 'Fi', 'L', 'D', 'F', 'Di', 'Li', 'F', 'L', 'F', 'F', 'Z', 'F', 'Li', 'Fi', 'L', 'D', 'F', 'Di', 'Li', 'F', 'L', 'F', 'Li', 'Fi', 'L', 'D', 'F', 'Di', 'Li', 'F', 'L', 'F', 'F', 'F', 'Li', 'Fi', 'L', 'D', 'F', 'Di', 'Li', 'F', 'L', 'F', 'Xi', 'Xi', 'X', 'X', 'F', 'F', 'R', 'F', 'Ri', 'F', 'R', 'F', 'F', 'Ri', 'F', 'F', 'Ri', 'Fi', 'R', 'Fi', 'Ri', 'F', 'F', 'R', 'F', 'F', 'F', 'F', 'Xi', 'Xi', 'X', 'X', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'R', 'R', 'F', 'D', 'Ui', 'R', 'R', 'Di', 'U', 'F', 'R', 'R', 'Z', 'Z', 'Z', 'Z', 'R', 'R', 'F', 'D', 'Ui', 'R', 'R', 'Di', 'U', 'F', 'R', 'R', 'Z', 'Di', 'Li', 'Ri', 'S', 'Ri', 'Ri', 'S', 'S', 'Ri', 'Fi', 'Fi', 'R', 'Si', 'Si', 'Ri', 'Ri', 'Si', 'R', 'Fi', 'Fi', 'L', 'D']
If someone rotated a corner of the cube before giving it to me, perhaps as a prank, this isn't caught by the current codebase; it just hangs indefinitely.
>>> from rubik.cube import Cube
>>> from rubik.solve import Solver
>>> s = Solver(Cube('orwowgwywgbgrgrbobowyggbrrbybrgowoygryrbbgoobyoyrywyww'.upper()))
>>> s.solve()
^Cā¦
For other non-solvable states, such as a flipped edge, the code does catch these.
But when it comes to rotated corners, it just enters an infinite loop.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ššš
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ā¤ļø Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.