Struct LeftDeadEnd

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

Represents a Left dead end; it is identified with its set of options.

Implementations§

Source§

impl LeftDeadEnd

Source

pub const ZERO: LeftDeadEnd

The zero game.

Source

pub fn new() -> Self

Constructs a new LeftDeadEnd with no options; i.e. the zero game. This is the same as LeftDeadEnd::default() and LeftDeadEnd::ZERO.

Source

pub fn with_options( options: impl IntoIterator<Item = impl Into<LeftDeadEnd>>, ) -> Self

Creates a new LeftDeadEnd given an iterable of elements that can each be converted into a LeftDeadEnd.

§Examples
let g = LeftDeadEnd::with_options(0..2);

assert_eq!(g.options(), vec![LeftDeadEnd::ZERO, LeftDeadEnd::integer(1)]);
Source

pub fn options(&self) -> &[Self]

Returns a borrowed slice to the options of the LeftDeadEnd.

§Examples
let g = LeftDeadEnd::ZERO;
assert!(g.options().is_empty());
let g = LeftDeadEnd::integer(4);
let h = LeftDeadEnd::integer(3);
assert_eq!(g.options(), vec!(h));
Source

pub fn options_iter(&self) -> Iter<'_, LeftDeadEnd>

Returns an iterator over the options of the LeftDeadEnd.

Source

pub fn novel_factors(&self) -> Vec<LeftDeadEnd>

Return the novel factors of a LeftDeadEnd.

If a sum g = h + k is novel, then, without loss of generality, h appears in every factorisation of g. But k, the counterpart to h, is not necessarily in the factors of the options of g, and so we have to build and check for it separately.

As of writing, no Left dead ends are known not to be uniquely factorisable, and so the output will likely be identical to LeftDeadEnd::factors.

Source

pub fn factors(&self) -> Vec<LeftDeadEnd>

Return the factors of the LeftDeadEnd. They will not be in canonical form when returned.

§Examples
let g = LeftDeadEnd::waiting(2) + 1;

let factors = g.factors();

assert_eq!(factors, vec![LeftDeadEnd::integer(1), LeftDeadEnd::waiting(2),
LeftDeadEnd::waiting(2) + 1, LeftDeadEnd::ZERO]);
let g = LeftDeadEnd::integer(3);

let factors = g.factors();

assert_eq!(factors, vec![LeftDeadEnd::integer(1), LeftDeadEnd::integer(2),
LeftDeadEnd::integer(3), LeftDeadEnd::ZERO]);
Source

pub fn is_atom(&self) -> bool

Returns whether or not the LeftDeadEnd is an atom; i.e. if it has precisely two factors.

§Examples
let g = LeftDeadEnd::ZERO;
assert!(!g.is_atom());

let g = LeftDeadEnd::integer(1);
assert!(g.is_atom());
Source

pub fn integer(rank: usize) -> Self

Returns the strict form of a negative integer of given rank.

§Examples
let g = LeftDeadEnd::ZERO;
let h = LeftDeadEnd::integer(0);
assert_eq!(g, h);
// The same form as the canonical form of -1 in normal play.
let g = LeftDeadEnd::integer(1);
// The same form as the canonical form of -2 in normal play.
let h = LeftDeadEnd::integer(2);
assert_eq!(&g + &g, h);
Source

pub fn waiting(rank: usize) -> Self

Returns the waiting game of given rank. Sometimes also called the perfect murder.

§Examples
let g = LeftDeadEnd::waiting(1);
let h = LeftDeadEnd::integer(1);
assert_eq!(g, h);
let g = LeftDeadEnd::ZERO;
let h = LeftDeadEnd::integer(1);
let k = LeftDeadEnd::waiting(2);
assert_eq!(k.options(), vec![g, h]);
Source

pub fn canonical(&self) -> Self

Returns the canonical (simplest) form of the LeftDeadEnd.

§Examples
let g = LeftDeadEnd::integer(1);
let h = LeftDeadEnd::waiting(2);
let k = LeftDeadEnd::with_options(vec![g.clone(), h.clone()]);

// The waiting game dominates the integer here.
assert_eq!(k.canonical().options(), vec![h]);
Source

pub fn is_waiting(&self) -> (usize, bool)

Returns whether or not the LeftDeadEnd is a canonical form waiting game in the form of a tuple (a, b), where a respresents the rank of the waiting game (if it is one), and b represents whether or not it is a waiting game.

Source

pub fn is_integer(&self) -> (usize, &LeftDeadEnd, bool)

Returns a 3-tuple (a, b, c), where a is the maximum rank of an integer that divides the LeftDeadEnd, b is the counterpart to the integer in the factorisation of the game, and c represents whether the game is an integer.

This function expects the LeftDeadEnd to be in canonical form!

§Examples
let g = LeftDeadEnd::integer(3);
let h = LeftDeadEnd::waiting(2);
let k = (&g + &h).canonical();

let (a, b, c) = k.is_integer();

// The maximum rank of an integer dividing `k` is 3.
assert_eq!(a, 3);

// The counterpart to the integer in the factorisation of `k` is `h` (by construction).
assert_eq!(b, &h);

// The game `k` is not an integer.
assert_eq!(c, false);
let g = LeftDeadEnd::integer(7);

let (a, b, c) = g.is_integer();

// The maximum rank of an integer dividing `g` is 7.
assert_eq!(a, 7);

// The counterpart to the integer in the factorisation of `g` is 0 (by construction).
assert_eq!(b, &LeftDeadEnd::ZERO);

// The game `g` *is* an integer.
assert_eq!(c, true);
Source

pub fn bound_length(&self) -> usize

Bounds the length of factorisations of the LeftDeadEnd. This bound is not always optimal.

Source

pub fn flex(&self) -> usize

Returns the flexibility of the LeftDeadEnd.

Source

pub fn birth(&self) -> usize

Returns the birthday of the LeftDeadEnd. Note that this is equivalent to its formal birthday, and hence there is no separate function for that. Also note that this is equivalent to max(self.term_lengths()).

Source

pub fn race(&self) -> usize

Returns the race of the LeftDeadEnd. Note that this is equivalent to min(self.term_lengths()).

Source

pub fn term_lengths(&self) -> Vec<usize>

Returns the set of terminal lengths of the LeftDeadEnd as a vector; there are no repeated entries. Note that min(self.term_lengths()) == self.race() and max(self.term_lengths()) == self.birth().

Trait Implementations§

Source§

impl<Rhs> Add<Rhs> for LeftDeadEnd
where Rhs: Into<LeftDeadEnd>,

Source§

type Output = LeftDeadEnd

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for &LeftDeadEnd

Source§

type Output = LeftDeadEnd

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for LeftDeadEnd

Source§

fn clone(&self) -> LeftDeadEnd

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for LeftDeadEnd

Will only format canonical form integers.

Source§

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

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

impl Default for LeftDeadEnd

Source§

fn default() -> Self

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

impl Display for LeftDeadEnd

Will format canonical form integers and waiting games.

Source§

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

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

impl From<usize> for LeftDeadEnd

Convert a usize into what would be the canonical form of a (negative) integer in normal play; i.e. an integer Left dead end.

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl Hash for LeftDeadEnd

The hash is not well-defined up to equivalence.

§Example

let g = LeftDeadEnd::waiting(2) + 1;
let h = (LeftDeadEnd::waiting(2) + 1).canonical();

let mut hasher = DefaultHasher::new();
g.hash(&mut hasher);
let first_hash = hasher.finish();

let mut hasher = DefaultHasher::new();
h.hash(&mut hasher);
let second_hash = hasher.finish();

assert_ne!(first_hash, second_hash);
Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for LeftDeadEnd

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 PartialOrd for LeftDeadEnd

Source§

fn partial_cmp(&self, other: &LeftDeadEnd) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
Source§

fn ge(&self, other: &LeftDeadEnd) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

impl Eq for LeftDeadEnd

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.