feat: Day 2 done

This commit is contained in:
2025-12-06 15:21:00 +00:00
parent d6a3b812eb
commit 8a4915eea1
10 changed files with 171 additions and 0 deletions

7
Day2/P1/Cargo.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "P1"
version = "0.1.0"

6
Day2/P1/Cargo.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
name = "P1"
version = "0.1.0"
edition = "2024"
[dependencies]

1
Day2/P1/example Normal file
View File

@@ -0,0 +1 @@
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124

31
Day2/P1/src/main.rs Normal file
View File

@@ -0,0 +1,31 @@
use std::fs;
fn main() {
println!("Day 2P1");
let contents = fs::read_to_string("test").expect("input not found");
let mut bad_count = 0;
for range in contents.split(",") {
let mut parts = range.split("-");
let first_id = parts.next().unwrap();
let last_id = parts.next().unwrap().trim();
bad_count += check_range(first_id, last_id);
}
print!("Total {bad_count}");
}
fn check_range(first: &str, last: &str) -> u64 {
let first_int: u64 = first.parse().unwrap();
let last_int: u64 = last.parse().unwrap();
let mut count = 0;
for n in first_int..=last_int {
let input = n.to_string();
let parts = input.split_at(input.len() / 2);
if parts.0 == parts.1 {
println!("{input} is invalid");
count += n;
}
}
count
}

1
Day2/P1/test Normal file
View File

@@ -0,0 +1 @@
7777742220-7777814718,3201990-3447830,49-86,653243-683065,91-129,24-41,1-15,2678-4638,1407-2511,221-504,867867-942148,1167452509-1167622686,9957459726-9957683116,379068-535983,757-1242,955118-1088945,297342-362801,548256-566461,4926-10075,736811-799457,1093342-1130060,620410-651225,65610339-65732429,992946118-993033511,5848473-5907215,17190619-17315301,203488-286290,15631-36109,5858509282-5858695889,87824047-87984031,1313113913-1313147594,795745221-795825571,46303-100636,4743038-4844422