day 23 part 1
This commit is contained in:
@@ -228,6 +228,9 @@ fn play(boss: Boss, hard: bool) -> i32 {
|
||||
let mut min_mana = i32::MAX;
|
||||
|
||||
while let Some(current) = queue.pop() {
|
||||
if current.boss.health < 1 {
|
||||
return current.wizard.spent;
|
||||
}
|
||||
if INTERACTIVE {
|
||||
let _ = std::io::stdin().read_line(&mut String::new()).unwrap();
|
||||
println!("{current:?}");
|
||||
@@ -289,14 +292,10 @@ fn play(boss: Boss, hard: bool) -> i32 {
|
||||
let armor = n.wizard.armor();
|
||||
let mut n = n.apply_effects();
|
||||
if n.boss.health < 1 {
|
||||
min_mana = min(min_mana, n.wizard.spent);
|
||||
queue.retain(|s| s.wizard.spent > min_mana);
|
||||
} else {
|
||||
n.wizard.health -= max(1, n.boss.damage - armor);
|
||||
if n.wizard.health > 0 && n.wizard.spent < min_mana {
|
||||
queue.push(n);
|
||||
}
|
||||
}
|
||||
queue.push(n);
|
||||
}
|
||||
}
|
||||
return min_mana;
|
||||
|
||||
80
src/day23.rs
80
src/day23.rs
@@ -1,18 +1,84 @@
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
|
||||
type Input = ();
|
||||
type Input = String;
|
||||
|
||||
#[aoc_generator(day22)]
|
||||
#[aoc_generator(day23)]
|
||||
fn parse(input: &str) -> Input {
|
||||
todo!()
|
||||
input.to_string()
|
||||
}
|
||||
|
||||
#[aoc(day22, part1)]
|
||||
fn part1(_: &Input) -> usize {
|
||||
0
|
||||
#[aoc(day23, part1)]
|
||||
fn part1(input: &Input) -> usize {
|
||||
let mut a = 0;
|
||||
let mut b = 0;
|
||||
let mut ip: i32 = 0;
|
||||
|
||||
let mem = input.lines().collect::<Vec<_>>();
|
||||
|
||||
while let Some(line) = mem.get(ip as usize) {
|
||||
let (lhs, rhs) = line.split_once(" ").unwrap();
|
||||
match lhs {
|
||||
"hlf" => {
|
||||
match rhs {
|
||||
"a" => a /= 2,
|
||||
"b" => b /= 2,
|
||||
_ => panic!("unknown register"),
|
||||
};
|
||||
}
|
||||
"tpl" => {
|
||||
match rhs {
|
||||
"a" => a *= 3,
|
||||
"b" => b *= 3,
|
||||
_ => panic!("unknown register"),
|
||||
};
|
||||
}
|
||||
"inc" => {
|
||||
match rhs {
|
||||
"a" => a += 1,
|
||||
"b" => b += 1,
|
||||
_ => panic!("unknown register"),
|
||||
};
|
||||
}
|
||||
"jmp" => {
|
||||
let offset = parse_offset(rhs);
|
||||
ip += offset - 1;
|
||||
}
|
||||
"jie" => {
|
||||
let (r, o) = rhs.split_once(", ").unwrap();
|
||||
let offset = parse_offset(o);
|
||||
let jump = match r {
|
||||
"a" => a % 2 == 0,
|
||||
"b" => b % 2 == 0,
|
||||
_ => panic!(),
|
||||
};
|
||||
if jump {
|
||||
ip += offset - 1;
|
||||
}
|
||||
}
|
||||
"jio" => {
|
||||
let (r, o) = rhs.split_once(", ").unwrap();
|
||||
let offset = parse_offset(o);
|
||||
let jump = match r {
|
||||
"a" => a == 1,
|
||||
"b" => b == 1,
|
||||
_ => panic!(),
|
||||
};
|
||||
if jump {
|
||||
ip += offset - 1;
|
||||
}
|
||||
}
|
||||
_ => panic!("unknown instruction"),
|
||||
}
|
||||
ip += 1;
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
#[aoc(day22, part2)]
|
||||
fn parse_offset(input: &str) -> i32 {
|
||||
input.parse().unwrap()
|
||||
}
|
||||
|
||||
#[aoc(day23, part2)]
|
||||
fn part2(_: &Input) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
@@ -15,5 +15,6 @@ mod day19;
|
||||
mod day20;
|
||||
mod day21;
|
||||
mod day22;
|
||||
mod day23;
|
||||
|
||||
aoc_lib! { year = 2015 }
|
||||
|
||||
Reference in New Issue
Block a user