diff --git a/src/tasks/day05.rs b/src/tasks/day05.rs index 554372c..85aea50 100644 --- a/src/tasks/day05.rs +++ b/src/tasks/day05.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::path::Path; pub type RAM = HashMap; @@ -14,6 +15,15 @@ pub fn run() { task2(ram.clone()); } +pub fn load_ram>(path: P) -> RAM { + let input = std::fs::read_to_string(path).unwrap(); + input + .split(",") + .enumerate() + .map(|(i, s)| (i, s.parse::().unwrap())) + .collect() +} + pub struct IntCodeComputer { input_storage: Vec, output_storage: Vec, @@ -169,6 +179,13 @@ impl IntCodeComputer { } } + pub fn run_single(&mut self, input: i128) -> i128 { + self.set_input(&[input]); + self.clear_output(); + self.run_until_input_empty(); + *self.get_output().first().unwrap() + } + pub fn run_until_end(&mut self) { if !self.run_until_input_empty() { panic!("There wasn't enough input given to run until the program halted");