Aoc 2023 day 1 part 1 finished, warming my fingers

This commit is contained in:
2023-12-04 09:00:17 +01:00
parent 2a60712f44
commit c414be2200
4 changed files with 1056 additions and 0 deletions

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,44 @@
fn solve_1(input: &str) -> u32 {
input
.lines()
.map(|l| {
// Digits are 0-9, so we know that if they
// are still 10 they haven't been changed
let mut first = 10;
let mut last = 10;
for c in l.chars() {
if let Some(digit) = c.to_digit(10) {
if first == 10 {
first = digit;
}
last = digit;
}
}
first * 10 + last
})
.sum()
}
fn main() {
println!("Hello, this is Patrick!");
let input_txt = include_str!("../input.txt");
let result_1 = solve_1(input_txt);
println!("The sum of all calibration values is {}", result_1);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_1() {
let test_input = include_str!("../test.txt");
assert_eq!(solve_1(test_input), 142);
}
}

View File

@@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet