pub struct LeftDeadEnd { /* private fields */ }
Expand description
Represents a Left dead end; it is identified with its set of options.
Implementations§
Source§impl LeftDeadEnd
impl LeftDeadEnd
Sourcepub const ZERO: LeftDeadEnd
pub const ZERO: LeftDeadEnd
The zero game.
Sourcepub fn new() -> Self
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
.
Sourcepub fn with_options(
options: impl IntoIterator<Item = impl Into<LeftDeadEnd>>,
) -> Self
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)]);
Sourcepub fn options(&self) -> &[Self]
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));
Sourcepub fn options_iter(&self) -> Iter<'_, LeftDeadEnd>
pub fn options_iter(&self) -> Iter<'_, LeftDeadEnd>
Returns an iterator over the options of the LeftDeadEnd
.
Sourcepub fn novel_factors(&self) -> Vec<LeftDeadEnd>
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
.
Sourcepub fn factors(&self) -> Vec<LeftDeadEnd>
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]);
Sourcepub fn is_atom(&self) -> bool
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());
Sourcepub fn integer(rank: usize) -> Self
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);
Sourcepub fn waiting(rank: usize) -> Self
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]);
Sourcepub fn canonical(&self) -> Self
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]);
Sourcepub fn is_waiting(&self) -> (usize, bool)
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.
Sourcepub fn is_integer(&self) -> (usize, &LeftDeadEnd, bool)
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);
Sourcepub fn bound_length(&self) -> usize
pub fn bound_length(&self) -> usize
Bounds the length of factorisations of the LeftDeadEnd
. This bound is not always
optimal.
Sourcepub fn flex(&self) -> usize
pub fn flex(&self) -> usize
Returns the flexibility of the LeftDeadEnd
.
Sourcepub fn birth(&self) -> usize
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())
.
Sourcepub fn race(&self) -> usize
pub fn race(&self) -> usize
Returns the race of the LeftDeadEnd
. Note that this is equivalent to
min(self.term_lengths())
.
Sourcepub fn term_lengths(&self) -> Vec<usize>
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 LeftDeadEndwhere
Rhs: Into<LeftDeadEnd>,
impl<Rhs> Add<Rhs> for LeftDeadEndwhere
Rhs: Into<LeftDeadEnd>,
Source§impl Add for &LeftDeadEnd
impl Add for &LeftDeadEnd
Source§impl Clone for LeftDeadEnd
impl Clone for LeftDeadEnd
Source§fn clone(&self) -> LeftDeadEnd
fn clone(&self) -> LeftDeadEnd
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for LeftDeadEnd
Will only format canonical form integers.
impl Debug for LeftDeadEnd
Will only format canonical form integers.
Source§impl Default for LeftDeadEnd
impl Default for LeftDeadEnd
Source§impl Display for LeftDeadEnd
Will format canonical form integers and waiting games.
impl Display for LeftDeadEnd
Will format canonical form integers and waiting games.
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.
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§impl Hash for LeftDeadEnd
The hash is not well-defined up to equivalence.
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§impl PartialEq for LeftDeadEnd
impl PartialEq for LeftDeadEnd
Source§impl PartialOrd for LeftDeadEnd
impl PartialOrd for LeftDeadEnd
impl Eq for LeftDeadEnd
Auto Trait Implementations§
impl Freeze for LeftDeadEnd
impl RefUnwindSafe for LeftDeadEnd
impl Send for LeftDeadEnd
impl Sync for LeftDeadEnd
impl Unpin for LeftDeadEnd
impl UnwindSafe for LeftDeadEnd
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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