R

RubiksCube

Simple library for exploring a Rubik's cube

f15c3289 Initial commit; · by Aaron

Usage

$ python3 solver.py -h
usage: solver.py [-h] -f STATEFILE [-l LOGLEVEL] [-m MAXDEPTH]

optional arguments:
  -h, --help            show this help message and exit
  -f STATEFILE, --state-file STATEFILE
                        JSON file containing cube data.
  -l LOGLEVEL, --log-level LOGLEVEL
                        DEBUG|INFO|WARNING|ERROR|CRITICAL
  -m MAXDEPTH, --max-depth MAXDEPTH
                        Max number of moves for solution. 8 might take a day.
                        9 might take a year.

Methods

Everything about this is super basic. The RubiksCube class utilizes a dictionary containing a 3x3 array for each face of the cube.

Rotating a face maps each individual square to its new location in the array.

The solver is 100% brute force with one optimization: don't do the same move twice in a row. See below for benchmark.

There is plenty of room for improvement.

Benchmark

Depth Seconds           Hours                Days
1     7.51E-05          2.08616256713867E-08 8.69234402974447E-10
2     0.005095720291138 1.41547785864936E-06 5.897824411039E-08
3     0.096453905105591 2.67927514182197E-05 1.11636464242582E-06
4     0.846158742904663 0.000235044095251    9.79350396880397E-06
5     17.1716315746307  0.00476989765962     0.000198745735817
6     291.108149528503  0.080863374869029    0.00336930728621
7     6492.00966076708  1.80333601687975     0.075139000703323
8     82340.502260004   22.87236173889       0.95301507245375
9     1392582.81363459  386.828559342942     16.1178566392892
10    26932679.8603269  7481.29996120191     311.720831716746
11    442059408.487385  122794.280135385     5116.42833897436
12    7370699820.7483   2047416.61687453     85309.0257031054
13    119587158616.281  33218655.171189      1384110.63213288
14    2153078857082.02  598077460.300561     24919894.17919

CPU Specs:
 Architecture:          x86_64
 CPU(s):                4
 On-line CPU(s) list:   0-3
 Thread(s) per core:    2
 Core(s) per socket:    2
 Socket(s):             1
 Vendor ID:             GenuineIntel
 CPU family:            6
 Model:                 61
 Model name:            Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz
 Stepping:              4
 CPU MHz:               2709.210
 CPU max MHz:           2900.0000
 L1d cache:             32K
 L1i cache:             32K
 L2 cache:              256K
 L3 cache:              3072K

Future Plans

Rethink the cube class. Can it be faster? Simpler?

Add distributed processing. Multiprocess.