Function advent_solutions::advent2017::day18::part1
[−]
[src]
pub fn part1(instructions: &[Instruction]) -> isize
For example:
set a 1
add a 2
mul a a
mod a 5
snd a
set a 0
rcv a
jgz a -1
set a 1
jgz a -2
- The first four instructions set
ato1, add2to it, square it, and then set it to itself modulo5, resulting in a value of4. - Then, a sound with frequency
4(the value ofa) is played. - After that,
ais set to0, causing the subsequentrcvandjgzinstructions to both be skipped (rcvbecauseais0, andjgzbecauseais not greater than0). - Finally,
ais set to1, causing the nextjgzinstruction to activate, jumping back two instructions to another jump, which jumps again to thercv, which ultimately triggers the recover operation.
At the time the recover operation is executed, the frequency of the
last sound played is 4.
let instructions = Instruction::list_from_bytes(input.as_bytes()) .to_full_result() .expect("Error parsing instructions"); assert_eq!(part1(&instructions), 4);
What is the value of the recovered frequency (the value of the most
recently played sound) the first time a rcv instruction is executed
with a non-zero value?