add day 1 and 2

This commit is contained in:
2024-11-24 20:04:57 -05:00
parent 35c01782b0
commit 5b7a6edbfb
20 changed files with 2526 additions and 0 deletions

1
2023/day1/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

16
2023/day1/Cargo.lock generated Normal file
View File

@@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day1"
version = "0.1.0"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.164"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f"

7
2023/day1/Cargo.toml Normal file
View File

@@ -0,0 +1,7 @@
[package]
name = "day1"
version = "0.1.0"
edition = "2021"
[dependencies]
libc = "0.2.164"

1000
2023/day1/src/input.txt Normal file

File diff suppressed because it is too large Load Diff

40
2023/day1/src/main.rs Normal file
View File

@@ -0,0 +1,40 @@
use std::io::{self, Read};
//use libc::{clock_gettime, timespec, CLOCK_PROCESS_CPUTIME_ID};
fn main() {
let mut sum = 0;
let mut data = String::new();
io::stdin().read_to_string(&mut data).unwrap();
/* let mut begin = timespec {
tv_sec: 0,
tv_nsec: 0,
};
unsafe {
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &mut begin);
}; */
for line in data.lines() {
let mut vec = Vec::new();
for c in line.chars() {
if c.is_digit(10) {
let f = c.to_digit(10).unwrap();
vec.push(f);
}
}
let mut sussy = vec.first().unwrap().to_owned();
sussy = sussy * 10 + vec.last().unwrap().to_owned();
sum += sussy;
println!("{sum}");
};
/* let mut end = timespec {
tv_sec: 0,
tv_nsec: 0,
};
unsafe {
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &mut end);
};
println!(
"time: {:.6}ms",
(end.tv_nsec - begin.tv_nsec) as f32 / 1000.0 / 1000.0
); */
}