Fix support for relative mode addressing in input
This commit is contained in:
parent
25cd57559e
commit
261b67afbb
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "icc"
|
name = "icc"
|
||||||
version = "1.1.0"
|
version = "1.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub struct Computer {
|
||||||
position: usize,
|
position: usize,
|
||||||
relative_base: i64,
|
relative_base: i64,
|
||||||
input: VecDeque<i64>,
|
input: VecDeque<i64>,
|
||||||
output: Vec<i64>,
|
pub output: Vec<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -119,7 +119,7 @@ impl Computer {
|
||||||
if self.input.len() == 0 {
|
if self.input.len() == 0 {
|
||||||
return Status::WaitingForInput;
|
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");
|
let input = self.input.pop_front().expect("Input queue empty... weird");
|
||||||
self.mem_put(dest, input);
|
self.mem_put(dest, input);
|
||||||
println!("Input: {}", input);
|
println!("Input: {}", input);
|
||||||
|
@ -485,4 +485,13 @@ mod tests {
|
||||||
c.run();
|
c.run();
|
||||||
assert_eq!(c.output[0], 1125899906842624);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue