aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar alecdwm 2019-12-10 23:35:43 +1000
committerGravatar alecdwm 2019-12-10 23:35:43 +1000
commit7a34c6179d6098f897e54308beeae1b5079419e9 (patch)
tree325cffa26bd0106f8378a7a04641c0f78834ea95
parentfff0ba67874010a8ba6ec64fcfc9a39893ba1603 (diff)
added 2019 day9 part2 solution
-rw-r--r--src/main.rs1
-rw-r--r--src/year_2019/day9.rs24
2 files changed, 25 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 259976b..b640f78 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -36,6 +36,7 @@ fn main() {
puzzle_solutions.insert("2019::day8::part1", advent_of_code::year_2019::day8::part1);
puzzle_solutions.insert("2019::day8::part2", advent_of_code::year_2019::day8::part2);
puzzle_solutions.insert("2019::day9::part1", advent_of_code::year_2019::day9::part1);
+ puzzle_solutions.insert("2019::day9::part2", advent_of_code::year_2019::day9::part2);
let command = match env::args().nth(1) {
Some(command) => command,
diff --git a/src/year_2019/day9.rs b/src/year_2019/day9.rs
index 1833a8c..c55638a 100644
--- a/src/year_2019/day9.rs
+++ b/src/year_2019/day9.rs
@@ -66,6 +66,30 @@ pub fn part1() {
);
}
+/// You now have a complete Intcode computer.
+///
+/// Finally, you can lock on to the Ceres distress signal! You just need to boost your sensors using the BOOST program.
+///
+/// The program runs in sensor boost mode by providing the input instruction the value 2. Once run, it will boost the sensors automatically, but it might take a few seconds to complete the operation on slower hardware. In sensor boost mode, the program will output a single value: the coordinates of the distress signal.
+///
+/// Run the BOOST program in sensor boost mode. What are the coordinates of the distress signal?
+pub fn part2() {
+ let input = crate::common::read_stdin_to_string();
+ let mut computer = IntcodeComputer::from(input.as_str());
+
+ let input_tx = computer.create_input();
+ let output_rx = computer.create_output();
+
+ const SENSOR_BOOST_MODE_ID: i64 = 2;
+ input_tx.send(SENSOR_BOOST_MODE_ID).unwrap();
+
+ computer.run();
+
+ let coordinates = output_rx.recv().unwrap();
+
+ println!("The coordinates of the distress signal: {}", coordinates);
+}
+
#[cfg(test)]
mod tests {
use super::*;