47 lines
1.1 KiB
Rust
47 lines
1.1 KiB
Rust
use shared::intcode::{IntCode, SimulateStep};
|
|
|
|
fn run_checks(mut ic: IntCode) {
|
|
ic.next_input = Some(1);
|
|
loop {
|
|
match ic.simulate_step() {
|
|
SimulateStep::Finished => break,
|
|
SimulateStep::Output(o) => println!("Check output: {}", o),
|
|
SimulateStep::WaitForInput => panic!("No further input"),
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let mut ic = include_str!("input.txt").parse::<IntCode>().unwrap();
|
|
run_checks(ic.clone());
|
|
|
|
ic.next_input = Some(2);
|
|
println!("BOOST: {}", ic.simulate_step().expect_output());
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod day9test {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn examples1() {
|
|
assert_eq!(
|
|
"109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99".parse::<IntCode>().unwrap().simulate_io(None),
|
|
[109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99],
|
|
);
|
|
assert_eq!(
|
|
"1102,34915192,34915192,7,4,7,99,0".parse::<IntCode>().unwrap().simulate_io(None),
|
|
[1219070632396864], // "16-digit number"
|
|
);
|
|
assert_eq!(
|
|
"104,1125899906842624,99".parse::<IntCode>().unwrap().simulate_io(None),
|
|
[1125899906842624],
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn examples2() {
|
|
// no examples
|
|
}
|
|
}
|