Added day 24 code for part 1 and 2

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2022-01-14 14:14:06 +01:00
parent bf62fa4e41
commit cf351b153a
No known key found for this signature in database
GPG Key ID: 0C87282F76E61283
4 changed files with 320 additions and 0 deletions

View File

@ -118,3 +118,8 @@ day-23:
stage: build stage: build
script: script:
- cd day23; cargo run --release ./input - cd day23; cargo run --release ./input
day-24:
stage: build
script:
- cd day24; cargo run --release ./input

8
day24/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day24"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

252
day24/input Normal file
View File

@ -0,0 +1,252 @@
inp w
mul x 0
add x z
mod x 26
div z 1
add x 11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 1
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 10
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 10
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 13
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 2
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -10
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 5
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 6
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 0
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 12
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 16
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 12
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -7
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 15
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 13
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 7
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -13
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 6
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x 0
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 5
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 6
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x 0
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 15
mul y x
add z y

55
day24/src/main.rs Normal file
View File

@ -0,0 +1,55 @@
use std::{fs, env};
fn read_input(path: &str) -> String {
return fs::read_to_string(path).expect("Cannot read file.");
}
fn parse_input(s: &str) -> Vec<(usize, usize, i32)> {
let mut v = vec![];
let mut p: Vec<(usize, i32)> = vec![];
let mut a = false;
let mut i = 0usize;
for (n, l) in s.lines().enumerate() {
let c = n % (s.lines().count() / 14);
if c == 0 && n != 0 { i += 1; }
let l = l.split_whitespace().collect::<Vec<&str>>();
if c == 4 { a = l[2].parse::<i32>().unwrap() == 1; }
else if c == 5 && !a {
let x = p.pop().unwrap();
let o = x.1 + l[2].parse::<i32>().unwrap();
if o >= 0 { v.push((i, x.0, o)); }
else { v.push((x.0, i, -o)); }
} else if c == 15 && a { p.push((i, l[2].parse::<i32>().unwrap())); }
}
return v;
}
fn get_max(l: &Vec<(usize, usize, i32)>) -> u64 {
let mut x = [0u64; 14];
for i in l {
x[i.0] = 9;
x[i.1] = (9 - i.2) as u64;
}
return x.iter().fold(0, |acc, i| acc * 10 + *i);
}
fn get_min(l: &Vec<(usize, usize, i32)>) -> u64 {
let mut x = [0u64; 14];
for i in l {
x[i.1] = 1;
x[i.0] = (1 + i.2) as u64;
}
return x.iter().fold(0, |acc, i| acc * 10 + *i);
}
fn main() {
let args: Vec<String> = env::args().collect();
for arg in args.iter().skip(1) {
let input = read_input(&arg);
let vec_in = parse_input(&input);
println!("[{}]", &arg);
println!("\t[Part 1] => Answer is '{}'.", get_max(&vec_in));
println!("\t[Part 2] => Answer is '{}'.", get_min(&vec_in));
}
}