Commit b696618f authored by Marcel Behrmann's avatar Marcel Behrmann

day(19): part 1 solved

parent 913b0a4d
109,424,203,1,21102,1,11,0,1106,0,282,21101,0,18,0,1105,1,259,2102,1,1,221,203,1,21102,31,1,0,1106,0,282,21101,38,0,0,1106,0,259,21002,23,1,2,21202,1,1,3,21102,1,1,1,21102,57,1,0,1106,0,303,2102,1,1,222,21001,221,0,3,21002,221,1,2,21101,0,259,1,21102,1,80,0,1106,0,225,21102,1,93,2,21102,1,91,0,1106,0,303,2101,0,1,223,21001,222,0,4,21102,1,259,3,21101,225,0,2,21101,225,0,1,21101,118,0,0,1106,0,225,20101,0,222,3,21102,1,120,2,21102,1,133,0,1106,0,303,21202,1,-1,1,22001,223,1,1,21101,0,148,0,1106,0,259,2102,1,1,223,21001,221,0,4,20102,1,222,3,21102,1,23,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21102,195,1,0,106,0,108,20207,1,223,2,20101,0,23,1,21101,-1,0,3,21102,1,214,0,1106,0,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,2101,0,-4,249,21201,-3,0,1,21201,-2,0,2,21202,-1,1,3,21101,0,250,0,1105,1,225,21202,1,1,-4,109,-5,2106,0,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2106,0,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,22102,1,-2,-2,109,-3,2106,0,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,21201,-2,0,3,21102,343,1,0,1106,0,303,1106,0,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,21201,-4,0,1,21101,0,384,0,1106,0,303,1105,1,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,21202,1,1,-4,109,-5,2106,0,0
109,424,203,1,21102,1,11,0,1106,0,282,21101,0,18,0,1105,1,259,2102,1,1,221,203,1,21102,31,1,0,1106,0,282,21101,38,0,0,1106,0,259,21002,23,1,2,21202,1,1,3,21102,1,1,1,21102,57,1,0,1106,0,303,2102,1,1,222,21001,221,0,3,21002,221,1,2,21101,0,259,1,21102,1,80,0,1106,0,225,21102,1,93,2,21102,1,91,0,1106,0,303,2101,0,1,223,21001,222,0,4,21102,1,259,3,21101,225,0,2,21101,225,0,1,21101,118,0,0,1106,0,225,20101,0,222,3,21102,1,120,2,21102,1,133,0,1106,0,303,21202,1,-1,1,22001,223,1,1,21101,0,148,0,1106,0,259,2102,1,1,223,21001,221,0,4,20102,1,222,3,21102,1,23,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21102,195,1,0,106,0,108,20207,1,223,2,20101,0,23,1,21101,-1,0,3,21102,1,214,0,1106,0,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,2101,0,-4,249,21201,-3,0,1,21201,-2,0,2,21202,-1,1,3,21101,0,250,0,1105,1,225,21202,1,1,-4,109,-5,2106,0,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2106,0,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,22102,1,-2,-2,109,-3,2106,0,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,21201,-2,0,3,21102,343,1,0,1106,0,303,1106,0,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,21201,-4,0,1,21101,0,384,0,1106,0,303,1105,1,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,21202,1,1,-4,109,-5,2106,0,0
\ No newline at end of file
......@@ -24,6 +24,11 @@ impl IntVM {
self.instr_ptr = 0;
self.is_halted = false;
for _ in 0..(1000*2048) {
self.memory.push(0);
}
}
#[allow(dead_code)]
......@@ -216,7 +221,7 @@ pub fn create_vm(input: &Vec<&str>) -> IntVM {
tick_length: 0,
};
for _ in 0..1000 {
for _ in 0..(1000*2048) {
vm.memory.push(0);
}
......
mod utils;
mod intvm;
use std::{thread, time};
use std::fs;
use std::collections::{HashMap, VecDeque};
const INPUT_FILE: &str = "input.txt";
const SHOW_GAME: bool = true;
fn main() {
let input = fs::read_to_string(INPUT_FILE).expect("Error reading input");
let input = input.lines();
let input: Vec<&str> = input.collect::<Vec<&str>>();
let file = &fs::read_to_string(INPUT_FILE).expect("Error reading input");
let input = get_input(file);
part_01(input.clone());
part_02(input.clone());
//println!("Result part 1: {}", part_01(&input));
println!("Result part 2: {}", part_02(&input));
}
#[allow(unused_variables)]
fn part_01(input: Vec<&str>) {
println!("Result of Part 1");
fn get_input(input: &String) -> Vec<&str> {
let codes = input.split(",");
codes.collect::<Vec<&str>>()
}
fn part_01(input: &Vec<&str>) -> i64 {
let mut vm = intvm::create_vm(input);
let mut count = 0;
for y in 0..50 {
let mut row = 0;
print!("{}|", y);
for x in 0..50 {
vm.input.push_back(x);
vm.input.push_back(y);
vm.run();
let output = vm.output.pop_back().unwrap();
print!("{}", output);
if output == 1 {
count += 1;
row += 1;
}
vm.reset();
}
println!("|{}", row);
}
count
}
#[allow(unused_variables)]
fn part_02(input: Vec<&str>) {
println!("Result of Part 2");
fn part_02(input: &Vec<&str>) -> i64{
let mut vm = intvm::create_vm(input);
let mut count = 0;
let mut r = 0;
let mut width = 0;
while width < 126 {
r += 1;
width = get_count_for_row(r);
}
let width_deeper = get_count_for_row(r+100);
println!("Row {} is 126", r);
println!("Row {} is {}", r+100, width_deeper);
count
}
fn get_count_for_row(row: i64) -> i64 {
let mut queue = VecDeque::from(vec![4, 4, 4, 3]);
let mut r = 0;
let mut width = 1;
while r < row {
let q = queue.pop_front().unwrap();
queue.push_back(q);
let mut qc = 0;
while r < row && qc < q {
r += 1;
qc += 1;
}
if r < row {
width += 1;
}
}
width
}
\ 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