Advent of Code 2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4 KiB

use super::{Value, IntCode, IntCodeIO};
pub fn add<I: IntCodeIO>(intcode: &mut IntCode<I>, argv: &Vec<Value>) {
intcode.write(argv[2].address.unwrap(), argv[0].value + argv[1].value);
}
pub fn mul<I: IntCodeIO>(intcode: &mut IntCode<I>, argv: &Vec<Value>) {
intcode.write(argv[2].address.unwrap(), argv[0].value * argv[1].value);
}
pub fn exit<I: IntCodeIO>(intcode: &mut IntCode<I>, _argv: &Vec<Value>) {
intcode.terminate();
}
pub fn cin<I: IntCodeIO>(intcode: &mut IntCode<I>, argv: &Vec<Value>) {
let value = intcode.io.get();
intcode.write(argv[0].address.unwrap(), value);
}
pub fn cout<I: IntCodeIO>(intcode: &mut IntCode<I>, argv: &Vec<Value>) {
intcode.io.put(argv[0].value)
}
pub fn jump_if_true<I: IntCodeIO>(intcode: &mut IntCode<I>, argv: &Vec<Value>) {
if argv[0].value != 0 {
intcode.jump(argv[1].value as usize)
}
}
pub fn jump_if_false<I: IntCodeIO>(intcode: &mut IntCode<I>, argv: &Vec<Value>) {
if argv[0].value == 0 {
intcode.jump(argv[1].value as usize)
}
}
pub fn lt<I: IntCodeIO>(intcode: &mut IntCode<I>, argv: &Vec<Value>) {
intcode.write(
argv[2].address.unwrap(),
if argv[0].value < argv[1].value { 1 } else { 0 }
);
}
pub fn eq<I: IntCodeIO>(intcode: &mut IntCode<I>, argv: &Vec<Value>) {
intcode.write(
argv[2].address.unwrap(),
if argv[0].value == argv[1].value { 1 } else { 0 }
);
}