Skip to main content

cube-python

PyPI version PyPI License GitHub

High-performance Rubik's Cube solver Python bindings powered by C/C++ FFI.


Installation

pip install cube-python

Quickstart

import pycube
from pycube import SolveError

# Default solved cube string representation
print(f"Target State: {pycube.CUBE_ID}")

# Validate state solvability
scrambled = pycube.facecube("U F U' L2 R L' D2 B")

if pycube.solvable(scrambled):
    try:
        # Find solution sequence
        solution = pycube.solve(scrambled,good=22)
        print(f"Solution: {solution}")

        # Apply solution to verify end state
        end_state = pycube.facecube(solution, scrambled)
        assert end_state == pycube.CUBE_ID

    except SolveError as e:
        print(f"Failed to solve cube: {e}")

📖 API Reference

import pycube
from pycube import SolveError, CUBE_ID, PermFormat

Functions

Function Description
solve(src,tgt=CUBE_ID,good=22) Solve cube state src; stops as soon as a solution <= good moves is found. Returns solution string or raises SolveError.
facecube(maneuver,cube=CUBE_ID) Applies move sequence (e.g., "U F U' L2") to a cube state and returns the new state.
solvable(cube) Returns True if the 54-character state string is physically solvable.
permutation(ms_or_cube,fmt=PermFormat.Cycle) Returns a permutation representation for a move sequence or state.

Constants & Exceptions

Name Type Description
CUBE_ID str Constant representing the standard solved state UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB.
PermFormat IntEnum Permutation output format. Members: Face,Cubie,Cycle. Defaults to Cycle.
SolveError Exception Raised when the state is invalid or unsolvable.

📄 License

MIT © coshz

Metadata

Release files for cube-python 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cube-python 0.5.0
File Size Uploaded
cube_python-0.5.0.tar.gz 22.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cube-python 0.5.0
File Interpreter ABI Platform
cube_python-0.5.0-cp312-cp312-macosx_10_15_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.15+ x86-64 Details

Total release size: 116.8 kB

Release files / cube_python-0.5.0.tar.gz

Download URL cube_python-0.5.0.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f4ded093234587f6ead071040f479b776ce534e2a0cc1ca64df7c6c3c6154df4
BLAKE2b-256 checksum
How to use checksums
92e832649cd2675ae0314cd8495da75b4346334463f447bf0c318d77e950b51e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.1

Release files / cube_python-0.5.0-cp312-cp312-macosx_10_15_x86_64.whl

Download URL cube_python-0.5.0-cp312-cp312-macosx_10_15_x86_64.whl
Size 94.7 kB
Tags CPython 3.12 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
d1d18d017d0ce75bd5f872ca9d9587a0d99490ee223122245bd829498c306aae
BLAKE2b-256 checksum
How to use checksums
014d7be221a48faf24b5f74e7e47e2e1982a1b7cec2998875a9345b942997a4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.1

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page