From 261b67afbb4e3a017010d2b3ac7c5b4daa1254fa Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Sun, 15 May 2022 14:23:19 -0400 Subject: [PATCH] Fix support for relative mode addressing in input --- icc/Cargo.toml | 2 +- icc/src/lib.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/icc/Cargo.toml b/icc/Cargo.toml index e72f5dc..d08a9c1 100644 --- a/icc/Cargo.toml +++ b/icc/Cargo.toml @@ -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 diff --git a/icc/src/lib.rs b/icc/src/lib.rs index cf22d49..98a8d6a 100644 --- a/icc/src/lib.rs +++ b/icc/src/lib.rs @@ -20,7 +20,7 @@ pub struct Computer { position: usize, relative_base: i64, input: VecDeque, - output: Vec, + pub output: Vec, } #[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); + } }