npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cube-solver

v2.4.1

Published

Solve Rubik's cube using the Kociemba algorithm.

Downloads

93

Readme

cube-solver

travis codecov

This module contains a collection of Rubik's cube solvers implemented in JavaScript. It can solve a given cube using the fantastic Kociemba two-phase algorithm, generate random state scrambles, solve steps such as the cross or the Roux first block, as well as provide a variety of different scramble types.

Installation

To install, simply run yarn install cube-solver or similar, and require the cube-solver module. You can also manually add the bundle file to your webpage using this unpkg link, in which case the solver will be available globally as cubeSolver.

Examples

// Get a new random-state scramble.
const scramble = cubeSolver.scramble();
// Solve the first block.
cubeSolver.solve(scramble, 'fb') // => R L2 B' U' L2 D' F'
// Get a ZBLL scramble.
cubeSolver.scramble('zbll'); // => R B2 R' U' L U' L U' F2 R2 U' B2 U R2 D' F2 U'

Notes

The full 3x3 solver is pretty slow compared to other solvers such as the GWT compiled version of min2phase - it rather aims to be simple and extensible. Unless explicitly initialized, the Kociemba solver initializes when solving the first cube, which usually takes around 2 seconds. Generating and solving a random cube takes around 100ms on average, but for some cubes this number can be quite high. The optimal EOLine, FB, Cross and XCross solvers initialize pretty quickly, with the exception of the XCross solver which also takes around 2 seconds. As a consequence, you probably want to use this library in conjunction with web workers.

Documentation

The solver exposes three main methods.

  • cubeSolver.scramble(type = '3x3') lets you generate scrambles for the entire cube or subsets of it --- see below for a list of available scramblers.
  • cubeSolver.solve(scramble, type = 'kociemba') lets you solve either the entire cube or a subset of it for a given scramble. See below for a list of available solvers.
  • cubeSolver.initialize(solver) lets you initialize solvers so that the first solve is quicker. See below for a list of available solvers. To speed up random-state scrambles, the Kociemba solver should be initialized.

In general, the solvers will put the feature being solved for on the bottom. For example, using normal orientation, solving for an XCross will yield a yellow cross with the front-left pair solved. To solve other positions, you can apply pre-moves to your scrambles. This example shows how to find a bottom-left yellow XCross:

const scramble = `U2 B2 D R' F R2 U2 L D R2 L2 F2 U R2 U' L2 D F2 R2`;
// Find an optimal solution for cross + the back left pair.
cubeSolver.solve(`y ${scramble}`); // => U L2 F' R' F' D L' D

Available scramble types

| Type | Description | |---------|-----------------------------------------| | 3x3 | A random-state 3x3 scrable. | | 2gll | A 2-generator last layer scramble. | | cmll | A Roux CMLL scramble. | | corners | A corners-only scramble. | | edges | An edges-only scramble. | | lse | A Roux LSE scramble. | | lsll | Scramble for last slot + last layer. | | pll | A PLL scramble. | | zbll | A ZBLL scramble. | | zzls | Scramble for ZZ last slot + last layer. |

Available solver types

| Type | Description | |----------|----------------------------------------------------| | kociemba | Solve the whole cube using the Kociemba algorithm. | | cross | Solve the CFOP cross. | | eoline | Solve the ZZ EOLine. | | fb | Solve the Roux first block, on the bottom left. | | xcross | Solve an extended CFOP cross. |