From 42861d1149ca892a3fc14c42df60225791833046 Mon Sep 17 00:00:00 2001 From: CherryKitten Date: Fri, 1 Dec 2023 13:36:43 +0100 Subject: [PATCH] Day One solution --- src/bin/run.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/src/bin/run.rs b/src/bin/run.rs index e43b0f6..268dc87 100644 --- a/src/bin/run.rs +++ b/src/bin/run.rs @@ -1,5 +1,7 @@ #![allow(unused)] +use std::fmt::format; + use aoc_2023::Args; use clap::Parser; @@ -11,7 +13,7 @@ fn main() { return; } - let path = format!("./inputs/{day}.txt"); + let path = format!("./inputs/{day}.txt"); let input = std::fs::read_to_string(path).unwrap(); match day { @@ -45,74 +47,131 @@ fn main() { } fn day_1(input: String) { - todo!() + let mut result = vec![]; + + // Yes this is very ugly, I don't care lol + let input = input.replace("one", "o1e"); + let input = input.replace("two", "t2o"); + let input = input.replace("three", "t3e"); + let input = input.replace("four", "f4r"); + let input = input.replace("five", "f5e"); + let input = input.replace("six", "s6x"); + let input = input.replace("seven", "s7n"); + let input = input.replace("eight", "e8t"); + let input = input.replace("nine", "n9e"); + + for value in input + .lines() + .map(|line| { + line.chars() + .filter(|char| char.is_numeric()) + .map(|char| char.to_string()) + .collect::() + }) + .collect::>() + { + let first = value.chars().next().unwrap(); + let second = match value.chars().last() { + None => first, + Some(v) => v, + }; + + result.push(format!("{first}{second}")); + } + + let result: usize = result.iter().map(|v| v.parse::().unwrap()).sum(); + + println!("{result:?}"); } + fn day_2(input: String) { todo!() } + fn day_3(input: String) { todo!() } + fn day_4(input: String) { todo!() } + fn day_5(input: String) { todo!() } + fn day_6(input: String) { todo!() } + fn day_7(input: String) { todo!() } + fn day_8(input: String) { todo!() } + fn day_9(input: String) { todo!() } + fn day_10(input: String) { todo!() } + fn day_11(input: String) { todo!() } + fn day_12(input: String) { todo!() } + fn day_13(input: String) { todo!() } + fn day_14(input: String) { todo!() } + fn day_15(input: String) { todo!() } + fn day_16(input: String) { todo!() } + fn day_17(input: String) { todo!() } + fn day_18(input: String) { todo!() } + fn day_19(input: String) { todo!() } + fn day_20(input: String) { todo!() } + fn day_21(input: String) { todo!() } + fn day_22(input: String) { todo!() } + fn day_23(input: String) { todo!() } + fn day_24(input: String) { todo!() }