Add D21P1

This commit is contained in:
kageru 2019-12-26 15:28:43 +01:00
parent 970ad53ce5
commit ec7bb8f408
4 changed files with 33 additions and 1 deletions

10
2019/21/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "d21"
version = "0.1.0"
authors = ["kageru <kageru@encode.moe>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
intcode = { path = "../intcode" }

1
2019/21/input Normal file

File diff suppressed because one or more lines are too long

21
2019/21/src/main.rs Normal file
View File

@ -0,0 +1,21 @@
use intcode::*;
fn main() {
let program = "NOT A J
NOT B T
OR T J
NOT C T
OR T J
AND D J
WALK
"
.chars()
.map(|c| c as i64)
.rev()
.collect();
let part1 = IntComputer::new(read_input(), 0, program)
.get_all_outputs()
.pop()
.unwrap();
println!("{}", part1);
}

View File

@ -128,7 +128,7 @@ impl IntComputer {
as usize,
},
['0', '3'] => Operation::Input {
value: self.params.pop().unwrap(),
value: self.params.pop().expect("Encountered input instruction with empty parameters"),
addr: self.get_next_address(get_mode(&full_opcode, ParameterPosition::First))
as usize,
},