Fix support for relative mode addressing in input

This commit is contained in:
Kienan Stewart 2022-05-15 14:23:19 -04:00
parent 25cd57559e
commit 261b67afbb
2 changed files with 12 additions and 3 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "icc"
version = "1.1.0"
version = "1.1.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -20,7 +20,7 @@ pub struct Computer {
position: usize,
relative_base: i64,
input: VecDeque<i64>,
output: Vec<i64>,
pub output: Vec<i64>,
}
#[derive(Debug)]
@ -119,7 +119,7 @@ impl Computer {
if self.input.len() == 0 {
return Status::WaitingForInput;
}
let dest = self.mem_get(self.position + 1) as usize;
let dest = self.absolute_address(self.position + 1, p1_mode);
let input = self.input.pop_front().expect("Input queue empty... weird");
self.mem_put(dest, input);
println!("Input: {}", input);
@ -485,4 +485,13 @@ mod tests {
c.run();
assert_eq!(c.output[0], 1125899906842624);
}
#[test]
fn day9_relative_mode_input() {
let program = vec![109, -2, 203, 2, 99];
let mut c = Computer::initialize(program, vec![1312]);
c.run();
println!("{:?}", c.memory);
assert_eq!(c.mem_get(0), 1312);
}
}