day 21 task 1
This commit is contained in:
1
input/day21.txt
Normal file
1
input/day21.txt
Normal file
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
||||
mod tasks;
|
||||
|
||||
fn main() {
|
||||
tasks::day16::run();
|
||||
tasks::day21::run();
|
||||
}
|
||||
|
||||
41
src/tasks/day21.rs
Normal file
41
src/tasks/day21.rs
Normal 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);
|
||||
}
|
||||
@@ -12,3 +12,4 @@ pub mod day12;
|
||||
pub mod day13;
|
||||
pub mod day14;
|
||||
pub mod day16;
|
||||
pub mod day21;
|
||||
|
||||
Reference in New Issue
Block a user