Skip to main content

Algorithm

Struct Algorithm 

Source
pub struct Algorithm { /* private fields */ }
Expand description

Represents a series of moves you can perform on a cube

§Example

 use rubiks_moves::moves::Algorithm;

 let alg = Algorithm::from("R U R' U'").unwrap();

Implementations§

Source§

impl Algorithm

Source

pub const fn new() -> Self

Creates an Algorithm that doesn’t have any moves

Source

pub fn simplify(&self) -> Self

Creates a shorter set of moves that still leaves the cube in the same state at the end

For example, combining U U into U2, or U U’ into nothing

§Example
use rubiks_moves::moves::Algorithm;

let alg = Algorithm::from("U U").unwrap();
let simplified = Algorithm::from("U2").unwrap();

assert_eq!(alg.simplify(), simplified);
Source

pub fn from(s: &str) -> Result<Self, MoveParseError>

Creates a Algorithm from a &str, mostly a convience function, or a way to take input from the user

§Errors

This errors when it is not given a space seperated list of single face turns e.g. U, F’, or D2

§Example
use rubiks_moves::moves::{Algorithm, Move, FaceTurn};

let parsed_alg = Algorithm::from("F' L").unwrap();
Source

pub fn inverse(&self) -> Self

Calulates the inverse for a whole algorthm at once.

If a given Algorithm is performed on a cube, then if Algorithm::inverse() is perfermed, the cube will return to its origonal state

§Example
use rubiks_moves::moves::Algorithm;

let original = Algorithm::from("F R U").unwrap();
let inversed = Algorithm::from("U' R' F'").unwrap();

assert_eq!(original.inverse(), inversed);
Source

pub fn commute(&self, other: &Self) -> Self

Combines two Algorithms in the form of ABA’B’

§Example
use rubiks_moves::moves::Algorithm;

let r = Algorithm::from("R").unwrap();
let u = Algorithm::from("U").unwrap();

let sexy = Algorithm::from("R U R' U'").unwrap();

assert_eq!(r.commute(&u), sexy);
Source

pub fn permute(&self, other: &Self) -> Self

Combines two Algorithms in the form of ABA’

§Example
use rubiks_moves::moves::Algorithm;

let r = Algorithm::from("R").unwrap();
let u = Algorithm::from("U").unwrap();

let r_u_r_rev = Algorithm::from("R U R'").unwrap();

assert_eq!(r.permute(&u), r_u_r_rev);
Source

pub fn sexy() -> Self

A sample Algorithm that is used often in speedcubing. Equvalent to R U R’ U’

Source

pub fn order(&self) -> u32

Determines how many times an algorithm needs to be repeated, to return to its origonal state

§Example
use rubiks_moves::moves::Algorithm;

let sexy = Algorithm::from("R U R' U'").unwrap();

assert_eq!(sexy.order(), 6);
Source

pub fn solves(&self, other: &Self) -> bool

Determines if an Algorithm solves another one

§Example
use rubiks_moves::moves::Algorithm;

let scramble = Algorithm::from("R' U' F D2 L2 F R2 U2 R2 B D2 L B2 D' B2 L' R' B D2 B U2 L U2 R' U' F").unwrap();
let solution = Algorithm::from("D2 F' D2 U2 F' L2 D R2 D B2 F L2 R' F' D U'").unwrap();

assert!(solution.solves(&scramble));

Trait Implementations§

Source§

impl Add<&Algorithm> for Algorithm

Source§

type Output = Algorithm

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Algorithm

Source§

fn clone(&self) -> Algorithm

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Algorithm

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Algorithm

Source§

fn default() -> Algorithm

Returns the “default value” for a type. Read more
Source§

impl Display for Algorithm

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> From<Vec<T>> for Algorithm
where T: Into<Move> + Copy,

Source§

fn from(moves: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl IntoIterator for Algorithm

Source§

type Item = Move

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Algorithm as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Algorithm

Source§

fn eq(&self, other: &Algorithm) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Algorithm

Source§

impl StructuralPartialEq for Algorithm

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.