Commit 90c35ea9 authored by Marcel Behrmann's avatar Marcel Behrmann

day(17): part 2 solved

parent 403df345
......@@ -216,7 +216,7 @@ pub fn create_vm(input: &Vec<&str>) -> IntVM {
tick_length: 0,
};
for _ in 0..2000 {
for _ in 0..(1000 * 1024) {
vm.memory.push(0);
}
......
......@@ -24,8 +24,6 @@ fn get_input(input: &String) -> Vec<&str> {
fn part_01(input: &Vec<&str>) -> i64{
let mut vm = intvm::create_vm(input);
println!("{}", vm.memory.len());
let mut map: HashMap<(i64, i64), u8> = HashMap::new();
let mut max_x = 0;
let mut max_y = 0;
......@@ -42,7 +40,7 @@ fn part_01(input: &Vec<&str>) -> i64{
map.insert((x, y), point);
if x > max_x {
max_x = x;
max_x = x + 1;
}
if y > max_y {
......@@ -63,11 +61,9 @@ fn part_01(input: &Vec<&str>) -> i64{
map.insert((max_x, max_y), 10);
let intersections = get_intersections(&map, max_x, max_y);
println!("Found {} intersections", intersections.len());
draw_map(&map, max_x, max_y);
let mut sum = 0;
for int in intersections {
sum += int.0 * int.1;
}
......@@ -84,12 +80,10 @@ fn get_intersections(map: &HashMap<(i64, i64), u8>, x: i64, y: i64) -> Vec<(i64,
let mut intersections: Vec<(i64, i64)> = Vec::new();
for y in 0..y {
for x in 0..(x+1) {
for x in 0..x {
let p = (x, y);
let pp = *map.get(&p).or(Some(&0)).unwrap();
print!("{}", pp as char);
if pp == 35 {
let mut intersection = true;
......@@ -113,9 +107,77 @@ fn get_intersections(map: &HashMap<(i64, i64), u8>, x: i64, y: i64) -> Vec<(i64,
intersections
}
fn draw_map(map: &HashMap<(i64, i64), u8>, x: i64, y: i64) -> () {
if !SHOW_GAME {
return;
}
for y in 0..y {
for x in 0..x {
print!("{}", *map.get(&(x, y)).or(Some(&64)).unwrap() as char);
}
}
}
#[allow(unused_variables)]
fn part_02(input: &Vec<&str>) -> i64{
println!("Result of Part 2");
let mut vm = intvm::create_vm(input);
0
}
\ No newline at end of file
// Wake up robot
vm.set_mem(0, 2);
vm.run();
print_output(&mut vm);
writeln_input(&mut vm, "A,B,A,B,C,A,B,C,A,C");
vm.run();
print_output(&mut vm);
writeln_input(&mut vm, "R,6,L,6,L,10");
vm.run();
print_output(&mut vm);
writeln_input(&mut vm, "L,8,L,6,L,10,L,6");
vm.run();
print_output(&mut vm);
writeln_input(&mut vm, "R,6,L,8,L,10,R,6");
vm.run();
print_output(&mut vm);
writeln_input(&mut vm, "n");
while !vm.is_halted {
vm.run();
}
vm.output.pop_back().unwrap()
}
fn print_output(vm: &mut intvm::IntVM) {
while vm.output.len() > 0 {
print!("{}", (vm.output.pop_front().unwrap() as u8) as char);
}
}
fn writeln_input(vm: &mut intvm::IntVM, input: &str) {
for c in input.chars() {
vm.input.push_back(c as i64);
}
vm.input.push_back(10);
}
/*
input.push_str("A,B,A,B,C,A,B,C,A,C");
input.push('\n');
input.push_str("R6,L6,L10");
input.push('\n');
input.push_str("L8,L6,L10,L6");
input.push('\n');
input.push_str("R6,L8,L10,R6");
input.push('\n');
input.push('y');
input.push('\n');
*/
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment