Enum advent_solutions::advent2017::day16::Move
[−]
[src]
pub enum Move {
Spin(usize),
Exchange(usize, usize),
Partner(char, char),
}The programs' dance consists of a sequence of dance moves:
Spin, written
sX, makesXprograms move from the end to the front, but maintain their order otherwise. (For example,s3onabcdeproducescdeab).assert_eq!( Move::Spin(3).apply(vec!['a', 'b', 'c', 'd', 'e']), ['c', 'd', 'e', 'a', 'b'] )
Exchange, written
xA/B, makes the programs at positionsAandBswap places.Partner, written
pA/B, makes the programs namedAandBswap places.
For example, with only five programs standing in a line (abcde), they
could do the following dance:
let starting_programs = vec!['a', 'b', 'c', 'd', 'e'];
s1, a spin of size1:eabcd.assert_eq!( Move::Spin(1).apply(starting_programs), ['e', 'a', 'b', 'c', 'd'] )
x3/4, swapping the last two programs:eabdc.assert_eq!( Move::Exchange(3, 4).apply(after_s1), ['e', 'a', 'b', 'd', 'c'] )
pe/b, swapping programseandb:baedc.assert_eq!( Move::Partner('e', 'b').apply(after_x34), ['b', 'a', 'e', 'd', 'c'] )
After finishing their dance, the programs end up in order baedc.
Variants
Spin(usize)Exchange(usize, usize)Partner(char, char)
Methods
impl Move[src]
pub fn apply(&self, programs: Vec<char>) -> Vec<char>[src]
pub fn list_from_bytes(i: &[u8]) -> IResult<&[u8], Vec<Move>, u32>
Trait Implementations
impl Copy for Move[src]
impl Clone for Move[src]
fn clone(&self) -> Move[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl PartialEq for Move[src]
fn eq(&self, __arg_0: &Move) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &Move) -> bool[src]
This method tests for !=.
impl Eq for Move[src]
impl Debug for Move[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result[src]
Formats the value using the given formatter. Read more