day 21 task 1

This commit is contained in:
Johannes
2019-12-21 11:49:40 +01:00
parent f2117fd2a8
commit 2040bc00aa
4 changed files with 44 additions and 1 deletions

1
input/day21.txt Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
mod tasks; mod tasks;
fn main() { fn main() {
tasks::day16::run(); tasks::day21::run();
} }

41
src/tasks/day21.rs Normal file
View File

@@ -0,0 +1,41 @@
use super::day05::*;
pub fn run() {
let input = std::fs::read_to_string("input/day21.txt").unwrap();
let ram: RAM = input
.split(",")
.enumerate()
.map(|(i, s)| (i, s.parse::<i128>().unwrap()))
.collect();
task1(ram.clone());
}
fn task1(ram: RAM) {
let p = r"NOT A J
NOT B T
OR T J
NOT C T
OR T J
AND D J
WALK
"
.to_string();
play(ram.clone(), p);
}
fn play(ram: RAM, program: String) {
let mut computer = IntCodeComputer::new(program.chars().map(|c| c as i128).collect(), ram);
computer.run_until_end();
let output = computer.get_output();
let s: String = output
.iter()
.map(|i| {
if *i > 255 {
format!("{}", i)
} else {
format!("{}", (*i as u8) as char)
}
})
.collect();
println!("{}", s);
}

View File

@@ -12,3 +12,4 @@ pub mod day12;
pub mod day13; pub mod day13;
pub mod day14; pub mod day14;
pub mod day16; pub mod day16;
pub mod day21;