2023-15: Implement part one

This commit is contained in:
Mathis 2023-12-23 22:13:46 +01:00
parent 186f9802b7
commit 50e0578690
5 changed files with 57 additions and 0 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7

View File

@ -0,0 +1,25 @@
pub mod part_one;
// pub mod part_two;
// pub mod common;
use crate::utils::solution::Solution;
use crate::utils::input_reader;
pub struct DaySolution ;
impl Solution for DaySolution {
fn input_path(&self) -> &'static str {
"input/2023/day_15/input.txt"
}
fn part_one(&self) -> String {
input_reader::read_input_file(self.input_path(), part_one::part_one)
}
fn part_two(&self) -> String {
// input_reader::read_input_file(self.input_path(), part_two::part_two)
String::from("Not implemented")
}
}

View File

@ -0,0 +1,28 @@
pub fn part_one(input_lines: Vec<String>) -> String {
let mut full_line: String = String::new();
for line in input_lines {
full_line.push_str(&line);
}
let init_sequences = full_line.split(',').collect::<Vec<&str>>();
let mut result = 0;
for seq in init_sequences {
result += hash_sequence(seq);
}
result.to_string()
}
fn hash_sequence(sequence: &str) -> usize {
let mut hash = 0;
for c in sequence.chars() {
hash += c as usize;
hash *= 17;
hash %= 256;
}
hash
}

View File

@ -12,6 +12,7 @@ pub mod day_11_cosmic_expantion;
pub mod day_12_hot_springs;
pub mod day_13_point_of_incidence;
pub mod day_14_parabolic_reflector_dish;
pub mod day_15_lens_library;
pub fn run(day: &str) {
let solution: Box<dyn Solution> = match day {
@ -27,6 +28,7 @@ pub fn run(day: &str) {
"12" => Box::new(day_12_hot_springs::DaySolution),
"13" => Box::new(day_13_point_of_incidence::DaySolution),
"14" => Box::new(day_14_parabolic_reflector_dish::DaySolution),
"15" => Box::new(day_15_lens_library::DaySolution),
_ => panic!("Invalid day specified"),
};