Solutions for 2022, as well as 2015-2018 and 2019 up to day 11
This commit is contained in:
commit
1895197c49
722 changed files with 375457 additions and 0 deletions
9
2019/day09_sensor_boost/Cargo.toml
Normal file
9
2019/day09_sensor_boost/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "day09_sensor_boost"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
intcode_processor = { path = "../common/intcode_processor" }
|
57
2019/day09_sensor_boost/challenge.txt
Normal file
57
2019/day09_sensor_boost/challenge.txt
Normal file
|
@ -0,0 +1,57 @@
|
|||
You've just said goodbye to the rebooted rover and left Mars when you receive a faint distress signal coming from the asteroid belt. It must be the Ceres monitoring station!
|
||||
|
||||
In order to lock on to the signal, you'll need to boost your sensors. The Elves send up the latest *BOOST* program - Basic Operation Of System Test.
|
||||
|
||||
While BOOST (your puzzle input) is capable of boosting your sensors, for tenuous safety reasons, it refuses to do so until the computer it runs on passes some checks to demonstrate it is a *complete Intcode computer*.
|
||||
|
||||
[Your existing Intcode computer](5) is missing one key feature: it needs support for parameters in *relative mode*.
|
||||
|
||||
Parameters in mode `2`, *relative mode*, behave very similarly to parameters in *position mode*: the parameter is interpreted as a position. Like position mode, parameters in relative mode can be read from or written to.
|
||||
|
||||
The important difference is that relative mode parameters don't count from address `0`. Instead, they count from a value called the *relative base*. The *relative base* starts at `0`.
|
||||
|
||||
The address a relative mode parameter refers to is itself *plus* the current *relative base*. When the relative base is `0`, relative mode parameters and position mode parameters with the same value refer to the same address.
|
||||
|
||||
For example, given a relative base of `50`, a relative mode parameter of `-7` refers to memory address `50 + -7 = *43*`.
|
||||
|
||||
The relative base is modified with the *relative base offset* instruction:
|
||||
|
||||
* Opcode `9` *adjusts the relative base* by the value of its only parameter. The relative base increases (or decreases, if the value is negative) by the value of the parameter.
|
||||
|
||||
For example, if the relative base is `2000`, then after the instruction `109,19`, the relative base would be `2019`. If the next instruction were `204,-34`, then the value at address `1985` would be output.
|
||||
|
||||
Your Intcode computer will also need a few other capabilities:
|
||||
|
||||
* The computer's available memory should be much larger than the initial program. Memory beyond the initial program starts with the value `0` and can be read or written like any other memory. (It is invalid to try to access memory at a negative address, though.)
|
||||
* The computer should have support for large numbers. Some instructions near the beginning of the BOOST program will verify this capability.
|
||||
|
||||
Here are some example programs that use these features:
|
||||
|
||||
* `109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99` takes no input and produces a [copy of itself](https://en.wikipedia.org/wiki/Quine_(computing)) as output.
|
||||
* `1102,34915192,34915192,7,4,7,99,0` should output a 16-digit number.
|
||||
* `104,1125899906842624,99` should output the large number in the middle.
|
||||
|
||||
The BOOST program will ask for a single input; run it in test mode by providing it the value `1`. It will perform a series of checks on each opcode, output any opcodes (and the associated parameter modes) that seem to be functioning incorrectly, and finally output a BOOST keycode.
|
||||
|
||||
Once your Intcode computer is fully functional, the BOOST program should report no malfunctioning opcodes when run in test mode; it should only output a single value, the BOOST keycode. *What BOOST keycode does it produce?*
|
||||
|
||||
Your puzzle answer was `2316632620`.
|
||||
|
||||
\--- Part Two ---
|
||||
----------
|
||||
|
||||
*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?*
|
||||
|
||||
Your puzzle answer was `78869`.
|
||||
|
||||
Both parts of this puzzle are complete! They provide two gold stars: \*\*
|
||||
|
||||
At this point, you should [return to your Advent calendar](/2019) and try another puzzle.
|
||||
|
||||
If you still want to see it, you can [get your puzzle input](9/input).
|
BIN
2019/day09_sensor_boost/day09_sensor_boost-.core
Normal file
BIN
2019/day09_sensor_boost/day09_sensor_boost-.core
Normal file
Binary file not shown.
33
2019/day09_sensor_boost/src/lib.rs
Normal file
33
2019/day09_sensor_boost/src/lib.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use intcode_processor::intcode_processor::{Cpu, OutputState};
|
||||
|
||||
pub fn run(input: &str) -> (isize, isize) {
|
||||
let mut cpu = Cpu::try_with_memory_from_str(input).unwrap();
|
||||
let mut cpu_2 = cpu.clone();
|
||||
cpu.set_input(1);
|
||||
let first = match cpu.run() {
|
||||
OutputState::DiagnosticCode(d) => d,
|
||||
e => panic!("Unexpected return code: {e:?}"),
|
||||
};
|
||||
cpu_2.set_input(2);
|
||||
let second = match cpu_2.run() {
|
||||
OutputState::DiagnosticCode(d) => d,
|
||||
e => panic!("Unexpected return code: {e:?}"),
|
||||
};
|
||||
(first, second)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fs::read_to_string;
|
||||
|
||||
fn read_file(name: &str) -> String {
|
||||
read_to_string(name).expect(&format!("Unable to read file: {name}")[..]).trim().to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_challenge() {
|
||||
let challenge_input = read_file("tests/challenge_input");
|
||||
assert_eq!(run(&challenge_input), (2316632620, 78869));
|
||||
}
|
||||
}
|
1
2019/day09_sensor_boost/tests/challenge_input
Normal file
1
2019/day09_sensor_boost/tests/challenge_input
Normal file
|
@ -0,0 +1 @@
|
|||
1102,34463338,34463338,63,1007,63,34463338,63,1005,63,53,1101,3,0,1000,109,988,209,12,9,1000,209,6,209,3,203,0,1008,1000,1,63,1005,63,65,1008,1000,2,63,1005,63,904,1008,1000,0,63,1005,63,58,4,25,104,0,99,4,0,104,0,99,4,17,104,0,99,0,0,1102,1,37,1000,1101,856,0,1029,1101,286,0,1025,1101,39,0,1004,1101,861,0,1028,1101,845,0,1026,1102,28,1,1002,1102,1,0,1020,1101,0,892,1023,1101,0,291,1024,1101,35,0,1018,1101,0,27,1006,1102,1,26,1011,1101,33,0,1019,1102,31,1,1014,1102,1,36,1010,1102,23,1,1007,1101,0,32,1016,1101,29,0,1008,1101,20,0,1001,1102,1,25,1015,1101,38,0,1017,1101,0,24,1012,1102,1,22,1005,1101,1,0,1021,1101,0,21,1003,1102,1,838,1027,1102,1,30,1013,1101,895,0,1022,1101,0,34,1009,109,7,1208,0,22,63,1005,63,201,1001,64,1,64,1105,1,203,4,187,1002,64,2,64,109,-6,2102,1,5,63,1008,63,24,63,1005,63,223,1105,1,229,4,209,1001,64,1,64,1002,64,2,64,109,17,21102,40,1,-6,1008,1012,40,63,1005,63,255,4,235,1001,64,1,64,1106,0,255,1002,64,2,64,109,-15,21108,41,41,9,1005,1012,277,4,261,1001,64,1,64,1106,0,277,1002,64,2,64,109,11,2105,1,10,4,283,1105,1,295,1001,64,1,64,1002,64,2,64,109,-9,21101,42,0,8,1008,1013,44,63,1005,63,315,1105,1,321,4,301,1001,64,1,64,1002,64,2,64,109,13,1206,3,337,1001,64,1,64,1106,0,339,4,327,1002,64,2,64,109,-10,1208,0,29,63,1005,63,361,4,345,1001,64,1,64,1106,0,361,1002,64,2,64,109,2,2108,27,-4,63,1005,63,383,4,367,1001,64,1,64,1105,1,383,1002,64,2,64,109,-4,1207,2,30,63,1005,63,405,4,389,1001,64,1,64,1105,1,405,1002,64,2,64,109,22,1205,-8,417,1106,0,423,4,411,1001,64,1,64,1002,64,2,64,109,-27,2108,19,0,63,1005,63,443,1001,64,1,64,1106,0,445,4,429,1002,64,2,64,109,13,21108,43,45,-1,1005,1013,461,1106,0,467,4,451,1001,64,1,64,1002,64,2,64,109,1,21107,44,45,4,1005,1019,485,4,473,1105,1,489,1001,64,1,64,1002,64,2,64,109,-8,2102,1,-7,63,1008,63,37,63,1005,63,515,4,495,1001,64,1,64,1106,0,515,1002,64,2,64,109,1,2107,38,-4,63,1005,63,533,4,521,1105,1,537,1001,64,1,64,1002,64,2,64,109,4,21107,45,44,1,1005,1013,553,1106,0,559,4,543,1001,64,1,64,1002,64,2,64,109,-7,2107,21,-4,63,1005,63,575,1106,0,581,4,565,1001,64,1,64,1002,64,2,64,109,9,1205,7,599,4,587,1001,64,1,64,1105,1,599,1002,64,2,64,109,-11,2101,0,-3,63,1008,63,40,63,1005,63,619,1105,1,625,4,605,1001,64,1,64,1002,64,2,64,109,1,2101,0,-2,63,1008,63,28,63,1005,63,651,4,631,1001,64,1,64,1106,0,651,1002,64,2,64,109,1,21102,46,1,7,1008,1012,44,63,1005,63,671,1106,0,677,4,657,1001,64,1,64,1002,64,2,64,109,4,1201,-7,0,63,1008,63,28,63,1005,63,699,4,683,1105,1,703,1001,64,1,64,1002,64,2,64,109,-6,1207,-3,36,63,1005,63,719,1105,1,725,4,709,1001,64,1,64,1002,64,2,64,109,-4,1201,6,0,63,1008,63,23,63,1005,63,745,1106,0,751,4,731,1001,64,1,64,1002,64,2,64,109,8,1202,-6,1,63,1008,63,20,63,1005,63,777,4,757,1001,64,1,64,1105,1,777,1002,64,2,64,109,5,1202,-5,1,63,1008,63,25,63,1005,63,801,1001,64,1,64,1105,1,803,4,783,1002,64,2,64,109,8,21101,47,0,-6,1008,1014,47,63,1005,63,829,4,809,1001,64,1,64,1106,0,829,1002,64,2,64,109,1,2106,0,6,1001,64,1,64,1106,0,847,4,835,1002,64,2,64,109,11,2106,0,-4,4,853,1105,1,865,1001,64,1,64,1002,64,2,64,109,-15,1206,3,883,4,871,1001,64,1,64,1106,0,883,1002,64,2,64,109,14,2105,1,-8,1105,1,901,4,889,1001,64,1,64,4,64,99,21102,1,27,1,21102,1,915,0,1106,0,922,21201,1,57564,1,204,1,99,109,3,1207,-2,3,63,1005,63,964,21201,-2,-1,1,21102,1,942,0,1105,1,922,22101,0,1,-1,21201,-2,-3,1,21101,957,0,0,1105,1,922,22201,1,-1,-2,1106,0,968,21202,-2,1,-2,109,-3,2106,0,0
|
0
2019/day09_sensor_boost/tests/sample_input
Normal file
0
2019/day09_sensor_boost/tests/sample_input
Normal file
Loading…
Add table
Add a link
Reference in a new issue