aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar alecdwm 2019-12-10 22:57:04 +1000
committerGravatar alecdwm 2019-12-10 22:57:04 +1000
commit3777648c6eeb1141ccab475f63193337073b845e (patch)
treec11f3a9c54641f3aafcdd810181fb01f0ad94dcf
parent0412d07b08770c8664bd83606b57fab9d9e3dfea (diff)
added intcode computer support for expanded working memory
-rw-r--r--src/year_2019/intcode_computer.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/year_2019/intcode_computer.rs b/src/year_2019/intcode_computer.rs
index d7815bf..a73e38b 100644
--- a/src/year_2019/intcode_computer.rs
+++ b/src/year_2019/intcode_computer.rs
@@ -357,13 +357,14 @@ pub struct IntcodeProgram {
impl IntcodeProgram {
pub fn get(&self, address: usize) -> i64 {
- *self
- .data
- .get(address)
- .unwrap_or_else(|| panic!("Failed to get data at address {}", address))
+ *self.data.get(address).unwrap_or(&0)
}
pub fn replace(&mut self, address: usize, replacement: i64) {
+ if self.data.len() <= address {
+ self.data.resize(address + 1, 0);
+ }
+
let integer = self
.data
.get_mut(address)