day 23 part 1
This commit is contained in:
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user