cube.print_cube() if args.min_memory: print("\n\n****************************************") print("--min-memory has been replaced by --fast") print("****************************************\n\n") log.info("rubiks-cube-solver.py end") #log.info("Memory : {:,} bytes".format(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)) log.info("Time : %s" % (end_time - start_time)) log.info("") if not cube.solved(): kociemba_string = cube.get_kociemba_string(False) #edge_swap_count = cube.get_edge_swap_count(edges_paired=True, orbit=None, debug=True) #corner_swap_count = cube.get_corner_swap_count(debug=True) #raise SolveError("cube should be solved but is not, edge parity %d, corner parity %d, kociemba %s" % # (edge_swap_count, corner_swap_count, kociemba_string)) raise SolveError("cube should be solved but is not") except (ImplementThis, SolveError, StuckInALoop, NoSteps, KeyError, NoPruneTableState): cube.enable_print_cube = True cube.print_cube_layout() cube.print_cube() cube.print_solution(False) print((cube.get_kociemba_string(True))) log.info("rubiks-cube-solver.py end") raise
def solve_non_table(self): """ 100% of the credit for this 2x2x2 solver goes to http://codegolf.stackexchange.com/questions/35002/solve-the-rubiks-pocket-cube In the codegolf challenge they defined the input as - - A B - - - - - - C D - - - - E F G H I J K L M N O P Q R S T - - U V - - - - - - W X - - - - But normally we number cubes like this 01 02 03 04 05 06 09 10 13 14 17 18 07 08 11 12 15 16 19 20 21 22 23 24 So we will define the former layout as "scramble" and the latter as "normal". Convert the normal layout (sys.argv[1] must be in the 'normal' layout) to the scramble layout. """ # 'normal' must be in U, R, F, D, L, B order # This is the order used by the kociemba 3x3x3 solver so # the rubiks-color-resolver uses this order normal = self.get_kociemba_string(False) log.info("NORMAL: %s" % normal) upper = normal[0:4] right = normal[4:8] front = normal[8:12] down = normal[12:16] left = normal[16:20] back = normal[20:24] ''' from pprint import pformat print "upper: %s" % pformat(upper) print "right: %s" % pformat(right) print "front: %s" % pformat(front) print "down: %s" % pformat(down) print "left: %s" % pformat(left) print "back: %s" % pformat(back) ''' scramble = [] scramble.extend(upper) scramble.append(left[0]) scramble.append(left[1]) scramble.append(front[0]) scramble.append(front[1]) scramble.append(right[0]) scramble.append(right[1]) scramble.append(back[0]) scramble.append(back[1]) scramble.append(left[2]) scramble.append(left[3]) scramble.append(front[2]) scramble.append(front[3]) scramble.append(right[2]) scramble.append(right[3]) scramble.append(back[2]) scramble.append(back[3]) scramble.extend(down) o = ''.join data = [{ ''.join((' ', x)[x in scramble[12] + scramble[19] + scramble[22]] for x in scramble): [] }, { ' ' * 4 + (scramble[12] * 2 + ' ' * 4 + scramble[19] * 2) * 2 + scramble[22] * 4: [] }] from pprint import pprint #pprint(data) wtf_table = [[ 0, 7, 2, 15, 4, 5, 6, 21, 16, 8, 3, 11, 12, 13, 14, 23, 17, 9, 1, 19, 20, 18, 22, 10 ], [ 0, 7, 2, 15, 4, 5, 6, 21, 16, 8, 3, 11, 12, 13, 14, 23, 17, 9, 1, 19, 20, 18, 22, 10 ], [ 0, 7, 2, 15, 4, 5, 6, 21, 16, 8, 3, 11, 12, 13, 14, 23, 17, 9, 1, 19, 20, 18, 22, 10 ], [ 0, 7, 2, 15, 4, 5, 6, 21, 16, 8, 3, 11, 12, 13, 14, 23, 17, 9, 1, 19, 20, 18, 22, 10 ], [ 2, 0, 3, 1, 6, 7, 8, 9, 10, 11, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ], [ 2, 0, 3, 1, 6, 7, 8, 9, 10, 11, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ], [ 2, 0, 3, 1, 6, 7, 8, 9, 10, 11, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ], [ 2, 0, 3, 1, 6, 7, 8, 9, 10, 11, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ], [ 0, 1, 13, 5, 4, 20, 14, 6, 2, 9, 10, 11, 12, 21, 15, 7, 3, 17, 18, 19, 16, 8, 22, 23 ], [ 0, 1, 13, 5, 4, 20, 14, 6, 2, 9, 10, 11, 12, 21, 15, 7, 3, 17, 18, 19, 16, 8, 22, 23 ], [ 0, 1, 13, 5, 4, 20, 14, 6, 2, 9, 10, 11, 12, 21, 15, 7, 3, 17, 18, 19, 16, 8, 22, 23 ], [ 0, 1, 13, 5, 4, 20, 14, 6, 2, 9, 10, 11, 12, 21, 15, 7, 3, 17, 18, 19, 16, 8, 22, 23 ]] for h in (0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1): for s, x in list(data[h].items()): for y in range(12): data[h][s] = x + [y - [1, -1, 1, 3][h * y % 4]] if s in data[1 - h]: # pprint(data[0][s]) # pprint(data[1][s]) try: result = ''.join('RUF'[x / 4] + " 2'"[x % 4] for x in data[0][s] + data[1][s][::-1]) except IndexError: print("Cube is already solved") sys.exit(0) result = result.replace('2', '2 ') result = result.replace("'", "' ") for step in result.strip().split(): self.rotate(step) return s = ''.join(s[x] for x in wtf_table[y]) raise SolveError("Could not find a solution")
cube.www_footer() if args.print_steps: cube.print_cube() print("\nMemory : {:,} bytes".format( resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)) print("Time : %s" % (end_time - start_time)) print("") if not cube.solved(): kociemba_string = cube.get_kociemba_string(False) edge_swap_count = cube.get_edge_swap_count(edges_paired=True, orbit=None, debug=True) corner_swap_count = cube.get_corner_swap_count(debug=True) raise SolveError( "cube should be solved but is not, edge parity %d, corner parity %d, kociemba %s" % (edge_swap_count, corner_swap_count, kociemba_string)) except (ImplementThis, SolveError, StuckInALoop, NoSteps, KeyError, NoPruneTableState): cube.enable_print_cube = True cube.print_cube_layout() cube.print_cube() cube.print_solution() print((cube.get_kociemba_string(True))) raise
def getResults(state): if sys.version_info < (3, 4): raise SystemError("Must be using Python 3.4 or higher") logging.basicConfig( level=logging.INFO, format="%(asctime)s %(filename)22s %(levelname)8s: %(message)s") log = logging.getLogger(__name__) log.info("rubiks-cube-solver.py begin") start_time = dt.datetime.now() parser = argparse.ArgumentParser() parser.add_argument("--print-steps", default=False, action="store_true", help="Display animated step-by-step solution") parser.add_argument("--debug", default=False, action="store_true", help="set loglevel to DEBUG") parser.add_argument("--no-comments", default=False, action="store_true", help="No comments in alg.cubing.net url") # CPU mode parser.add_argument( "--min-memory", default=False, action="store_true", help="Load smaller tables to use less memory...takes longer to run", ) parser.add_argument("--fast", default=True, action="store_true", help="Find a solution quickly") parser.add_argument("--normal", default=False, action="store_true", help="Find a shorter solution but takes longer") parser.add_argument("--slow", default=False, action="store_true", help="Find shortest solution we can, takes a while") action = parser.add_mutually_exclusive_group(required=False) parser.add_argument("--openwith", default=None, type=str, help="Colors for sides U, L, etc") parser.add_argument("--colormap", default=None, type=str, help="Colors for sides U, L, etc") parser.add_argument( "--order", type=str, default="URFDLB", help="order of sides in --state, default kociemba URFDLB") parser.add_argument("--solution333", type=str, default=None, help="cube explorer optimal steps for solving 3x3x3") parser.add_argument( "--state", type=str, help="Cube state", # no longer used # parser.add_argument('--test', default=False, action='store_true') # 2x2x2 # default='DLRRFULLDUBFDURDBFBRBLFU') # default='UUUURRRRFFFFDDDDLLLLBBBB') # 3x3x3 # default='RRBBUFBFBRLRRRFRDDURUBFBBRFLUDUDFLLFFLLLLDFBDDDUUBDLUU') # default='UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB') # solved # 4x4x4 # default='DRFDFRUFDURDDLLUFLDLLBLULFBUUFRBLBFLLUDDUFRBURBBRBDLLDURFFBBRUFUFDRFURBUDLDBDUFFBUDRRLDRBLFBRRLB') # xyzzy test cube # default='FLDFDLBDFBLFFRRBDRFRRURBRDUBBDLURUDRRBFFBDLUBLUULUFRRFBLDDUULBDBDFLDBLUBFRFUFBDDUBFLLRFLURDULLRU') # TPR cube # default="BRBLLLBRDLBBDDRRFUDFUDUDFUDDDRURBBBUUDRLFRDLLFBRFLRFLFFFBRULDRUBUBBLDBFRDLLUBUDDULFLRRFLFUBFUFUR", ) # default='UUUUUUUUUUUUUUUURRRRRRRRRRRRRRRRFFFFFFFFFFFFFFFFDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLBBBBBBBBBBBBBBBB') # solved # 5x5x5 # default='RFFFUDUDURBFULULFDBLRLDUFDBLUBBBDDURLRDRFRUDDBFUFLFURRLDFRRRUBFUUDUFLLBLBBULDDRRUFUUUBUDFFDRFLRBBLRFDLLUUBBRFRFRLLBFRLBRRFRBDLLDDFBLRDLFBBBLBLBDUUFDDD') # https://www.speedsolving.com/forum/threads/arnauds-5x5x5-edge-pairing-method-examples.1447/ # default='LDFRDDUUUUFUUUBLUUUFLDFDRFDDFBBRRRULRRRBFRRRURFRFDUBDRUBFFFUBFFFUUFFFRLDLRFDLBDDLDDDRDDDDUDDDDUULDLFBFLFFULLLRFLLLRLLLLRRBLBBRBULULBBBRUBBBRBBBBULBRFB') # default='UDLFDLDDLUFDUBRLBDLFLRBFRBLBBFUDURDULRRBRLFUURBUFLUBDUDRURRRBUFUFFFRUFFLDUURURFFULFFRLFDBRRFRDDBRFBBLBRDFBBBBUDDLLLDBUULUDULDLDDLBRRLRLUBBFFBDLFBDDLFR') # default='UUUUUUUUUUUUUUUUUUUUUUUUURRRRRRRRRRRRRRRRRRRRRRRRRFFFFFFFFFFFFFFFFFFFFFFFFFDDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLLBBBBBBBBBBBBBBBBBBBBBBBBB') # solved # default='DFFURRULDLDLURLBDDRRBFRURFBFBFRBDLBBFRBLRFBRBBFLULDLBLULLFRUBUFLDFFLDULDDLUURRDRFBRLULUDRBDUUUBBRFFDBDFURDBBDDRULBUDRDLLLBDRFDLRDLLFDBBUFBRURFFUFFUUFU') # step10 takes 2s # default='URUBFUUFRDFFUUFLRDBLLBDDDLUULRDLDUBDLRBBLFLBRBFUUBBRBFFUDLFLLBFUFUDRLBFUBBURRLLRUFRDUFFDFRFUBRBBDRFRFLLFURLLFBRBLUDRDDRRDRRFDUDLFLDLUUDUDBRBBBRBDDLDFL') # step10 takes 9s # default='RFUBLFUBRULLUDDRLRLLFFFLUBDBLBFFUFLFURBFFLDDLFFBBRLUUDRRDLLLRDFFLBBLFURUBULBRLBDRUURDRRDFURDBUUBBFBUDRUBURBRBDLFLBDFBDULLDBBDDDRRFURLDUDUBRDFRFFDFDRLU') # step10 takes 6s, centers take 37 steps :( # 6x6x6 # default='FBDDDFFUDRFBBLFLLURLDLLUFBLRFDUFLBLLFBFLRRBBFDRRDUBUFRBUBRDLUBFDRLBBRLRUFLBRBDUDFFFDBLUDBBLRDFUUDLBBBRRDRUDLBLDFRUDLLFFUUBFBUUFDLRUDUDBRRBBUFFDRRRDBULRRURULFDBRRULDDRUUULBLLFDFRRFDURFFLDUUBRUFDRFUBLDFULFBFDDUDLBLLRBL') # default='UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB') # solved # defult='xxxxxxxDRRLxxLDDBxxLUUDxxFRDUxxxxxxxxxxxxxxBBLBxxURFUxxDRBDxxDFDLxxxxxxxxxxxxxxULLRxxUFLLxxBLFRxxBBRDxxxxxxxxxxxxxxLFBRxxBUUFxxFDDFxxURUFxxxxxxxxxxxxxxRFDLxxURFUxxUBBFxxRULDxxxxxxxxxxxxxxBBLFxxFLLRxxDRBBxxFDRUxxxxxxx') # good step20 IDA test # 7x7x7 # default='DBDBDDFBDDLUBDLFRFRBRLLDUFFDUFRBRDFDRUFDFDRDBDBULDBDBDBUFBUFFFULLFLDURRBBRRBRLFUUUDUURBRDUUURFFFLRFLRLDLBUFRLDLDFLLFBDFUFRFFUUUFURDRFULBRFURRBUDDRBDLLRLDLLDLUURFRFBUBURBRUDBDDLRBULBULUBDBBUDRBLFFBLRBURRUFULBRLFDUFDDBULBRLBUFULUDDLLDFRDRDBBFBUB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DBBFUDFUUDLUDDRFDDDFRRRBUDRBFBBULLUFBLRLFLLBRRRRUBDRFLFDFDBLRFLURULULFFBUUUUFDBBLDLUBBRUBBBRBFLULLBLUUULLUBFFDULDFFBFFFUFFDUDRFBUFLDDLURFLRFLRFBUUBLRFDDRULUUUFFRDDBLRDULFURUDDBDLBBUUBFURFRFBRLBUULBLDDDBUBRFFULLUDFFDLDFUBLLBLDFFDDLBDUFUFFLBBBUBULDDFBRRFFLDUDDFRBLRRDDUDLBDBLURBUDBRRLUBBDRFBUFRDRDRBBDULBUFFDRBBDFBUULFFRLLDURRRDFFUUFULDULURLDLUUUDLBBUDLDRFBDBBDLUFBRRFDFLLDLFDBRBBRFUDDDBURDRBUBRUBDUBLDLLDLURLDFDBRUBDLDFRRRBRLULFRFLDRLBUBRUBLFBFDFFLFRFDFLBRULLRBLDRBBFURRRDUUULLULLDLBLBBDFBUUUBRRUFFBRUDBFRDFDLFLFFRFFFFRULDFFDFRUBBBRURBUFLBDFBBBBBRRRLFLFBDRRUFLURDDLRRBRLLFURRURBRFLLLFFURBFULFRFFBLDUUUUBDDUFFDRBRLDDFRBULDDDFFRURUFLDRFLDFBLRUFFUBBDFFDBLLDBDUBDLDLUDFBFLRULRRBDBLRBLDLUURRLLRULDBLBLLRRFDDRBBRBUBDDULDRFBFBBFLUFBLUULDDFDBRLLUBUBBDFBBLBBUBLULDRUDBLRULDUDLUFRRDLLUDDBUFLFLBUFUURFDRDLBURLLRRRULRBFFRRBRFBUBRBUUFRLRDRDLBBRFLLLDDBRFUFRBULFLFDRDDRRDBF') args = parser.parse_args() args.state = state if "G" in args.state: args.state = args.state.replace("G", "F") args.state = args.state.replace("Y", "D") args.state = args.state.replace("O", "L") args.state = args.state.replace("W", "U") if args.debug: log.setLevel(logging.DEBUG) try: size = int(sqrt((len(args.state) / 6))) if args.slow: cpu_mode = "slow" elif args.normal: cpu_mode = "normal" elif args.fast: cpu_mode = "fast" else: raise Exception("What CPU mode to use?") if size == 2: # rubiks cube libraries from rubikscubennnsolver.RubiksCube222 import RubiksCube222 cube = RubiksCube222(args.state, args.order, args.colormap, args.debug) elif size == 3: # rubiks cube libraries from rubikscubennnsolver.RubiksCube333 import RubiksCube333 cube = RubiksCube333(args.state, args.order, args.colormap, args.debug) elif size == 4: # rubiks cube libraries from rubikscubennnsolver.RubiksCube444 import RubiksCube444 cube = RubiksCube444(args.state, args.order, args.colormap, avoid_pll=True, debug=args.debug) elif size == 5: # rubiks cube libraries from rubikscubennnsolver.RubiksCube555 import RubiksCube555 cube = RubiksCube555(args.state, args.order, args.colormap, args.debug) elif size == 6: # rubiks cube libraries from rubikscubennnsolver.RubiksCube666 import RubiksCube666 cube = RubiksCube666(args.state, args.order, args.colormap, args.debug) elif size == 7: # rubiks cube libraries from rubikscubennnsolver.RubiksCube777 import RubiksCube777 cube = RubiksCube777(args.state, args.order, args.colormap, args.debug) elif size % 2 == 0: # rubiks cube libraries from rubikscubennnsolver.RubiksCubeNNNEven import RubiksCubeNNNEven cube = RubiksCubeNNNEven(args.state, args.order, args.colormap, args.debug) else: # rubiks cube libraries from rubikscubennnsolver.RubiksCubeNNNOdd import RubiksCubeNNNOdd cube = RubiksCubeNNNOdd(args.state, args.order, args.colormap, args.debug) if args.openwith: cube.print_cube() for step in args.openwith.split(): cube.rotate(step) cube.cpu_mode = cpu_mode log.info("CPU mode %s" % cube.cpu_mode) cube.sanity_check() cube.print_cube() cube.www_header() cube.www_write_cube("Initial Cube") try: if args.solution333: solution333 = reverse_steps(args.solution333.split()) else: solution333 = [] cube.solve(solution333) except NotSolving: if cube.heuristic_stats: log.info("%s: heuristic_stats raw\n%s\n\n" % (cube, pformat(cube.heuristic_stats))) for (key, value) in cube.heuristic_stats.items(): cube.heuristic_stats[key] = int(median(value)) log.info("%s: heuristic_stats median\n%s\n\n" % (cube, pformat(cube.heuristic_stats))) sys.exit(0) else: raise end_time = dt.datetime.now() log.info("Final Cube") cube.print_cube() res = cube.print_solution(not args.no_comments) log.info( "*********************************************************************************" ) log.info( "See /tmp/rubiks-cube-NxNxN-solver/index.html for more detailed solve instructions" ) log.info( "*********************************************************************************\n" ) # Now put the cube back in its initial state and verify the solution solves it solution = cube.solution cube.re_init() len_steps = len(solution) for (i, step) in enumerate(solution): if args.print_steps: print(("Phase : %s" % cube.phase())) print(("Move %d/%d: %s" % (i + 1, len_steps, step))) cube.rotate(step) www_desc = "Phase: %s<br>\nCube After Move %d/%d: %s<br>\n" % ( cube.phase(), i + 1, len_steps, step) cube.www_write_cube(www_desc) if args.print_steps: cube.print_cube() print("\n\n\n\n") cube.www_footer() if args.print_steps: cube.print_cube() if args.min_memory: print("\n\n****************************************") print("--min-memory has been replaced by --fast") print("****************************************\n\n") log.info("rubiks-cube-solver.py end") log.info("Memory : {:,} bytes".format( resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)) log.info("Time : %s" % (end_time - start_time)) log.info("") success = True if not cube.solved(): kociemba_string = cube.get_kociemba_string(False) # edge_swap_count = cube.get_edge_swap_count(edges_paired=True, orbit=None, debug=True) # corner_swap_count = cube.get_corner_swap_count(debug=True) # raise SolveError("cube should be solved but is not, edge parity %d, corner parity %d, kociemba %s" % # (edge_swap_count, corner_swap_count, kociemba_string)) raise SolveError("cube should be solved but is not") except (ImplementThis, SolveError, StuckInALoop, NoSteps, KeyError, NoPruneTableState, InvalidCubeReduction): cube.enable_print_cube = True cube.print_cube_layout() cube.print_cube() res = cube.print_solution(False) success = True print((cube.get_kociemba_string(True))) log.info("rubiks-cube-solver.py end") raise return res, success