Struct advent_solutions::advent2017::day08::Instruction
[−]
[src]
pub struct Instruction<'a> { /* fields omitted */ }Each instruction consists of several parts: the register to modify,
whether to increase or decrease that register's value, the amount by
which to increase or decrease it, and a condition. If the condition
fails, skip the instruction without modifying the register. The
registers all start at 0. The instructions look like this:
b inc 5 if a > 1
a inc 1 if b < 5
c dec -10 if a >= 1
c inc -20 if c == 10
These instructions would be processed as follows:
- Because
astarts at0, it is not greater than1, and sobis not modified. -
ais increased by1(to1) becausebis less than5(it is0). -
cis decreased by-10(to10) becauseais now greater than or equal to1(it is1). -
cis increased by-20(to-10) becausecis equal to10.
After this process, the largest value in any register is 1.
You might also encounter <= (less than or equal to) or != (not equal
to). However, the CPU doesn't have the bandwidth to tell you what all
the registers are named, and leaves that to you to determine.
Methods
impl<'a> Instruction<'a>[src]
pub fn from_bytes(i: &[u8]) -> IResult<&[u8], Instruction, u32>
pub fn list_from_bytes(i: &[u8]) -> IResult<&[u8], Vec<Instruction>, u32>
pub fn exec(&self, registers: &mut HashMap<&'a str, isize>)[src]
Trait Implementations
impl<'a> Copy for Instruction<'a>[src]
impl<'a> Clone for Instruction<'a>[src]
fn clone(&self) -> Instruction<'a>[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<'a> PartialEq for Instruction<'a>[src]
fn eq(&self, __arg_0: &Instruction<'a>) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &Instruction<'a>) -> bool[src]
This method tests for !=.
impl<'a> Eq for Instruction<'a>[src]
impl<'a> Debug for Instruction<'a>[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result[src]
Formats the value using the given formatter. Read more