day 21 task 2
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
use super::day05::*;
|
use super::day05::*;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
let input = std::fs::read_to_string("input/day21.txt").unwrap();
|
let input = std::fs::read_to_string("input/day21.txt").unwrap();
|
||||||
let ram: RAM = input
|
let ram: RAM = input
|
||||||
@@ -7,7 +8,7 @@ pub fn run() {
|
|||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, s)| (i, s.parse::<i128>().unwrap()))
|
.map(|(i, s)| (i, s.parse::<i128>().unwrap()))
|
||||||
.collect();
|
.collect();
|
||||||
task1(ram.clone());
|
task2(ram.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn task1(ram: RAM) {
|
fn task1(ram: RAM) {
|
||||||
@@ -23,6 +24,29 @@ WALK
|
|||||||
play(ram.clone(), p);
|
play(ram.clone(), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn task2(ram: RAM) {
|
||||||
|
// jump if NOT(A and B and C) and D and (H or (E and I) or (E and F))
|
||||||
|
let p = r"OR H J
|
||||||
|
OR E T
|
||||||
|
AND I T
|
||||||
|
OR T J
|
||||||
|
NOT E T
|
||||||
|
NOT T T
|
||||||
|
AND F T
|
||||||
|
OR T J
|
||||||
|
AND D J
|
||||||
|
NOT A T
|
||||||
|
NOT T T
|
||||||
|
AND B T
|
||||||
|
AND C T
|
||||||
|
NOT T T
|
||||||
|
AND T J
|
||||||
|
RUN
|
||||||
|
"
|
||||||
|
.to_string();
|
||||||
|
play(ram.clone(), p);
|
||||||
|
}
|
||||||
|
|
||||||
fn play(ram: RAM, program: String) {
|
fn play(ram: RAM, program: String) {
|
||||||
let mut computer = IntCodeComputer::new(program.chars().map(|c| c as i128).collect(), ram);
|
let mut computer = IntCodeComputer::new(program.chars().map(|c| c as i128).collect(), ram);
|
||||||
computer.run_until_end();
|
computer.run_until_end();
|
||||||
|
|||||||
Reference in New Issue
Block a user