Restructure folders

This commit is contained in:
2023-12-02 00:29:50 +01:00
parent 96c71f3f93
commit 574a8ef380
10 changed files with 0 additions and 0 deletions

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

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

7
2023/day1/part1/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 = 3
[[package]]
name = "day1"
version = "0.1.0"

View File

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

1000
2023/day1/part1/input Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,44 @@
fn main() {
let input = std::fs::read_to_string("./input").unwrap();
struct FirstLast {
first: Option<u32>,
last: Option<u32>,
}
impl FirstLast {
fn new() -> Self {
Self {
first: None,
last: None,
}
}
fn record(&mut self, n: u32) {
if self.first.is_none() {
self.first = Some(n)
} else {
self.last = Some(n)
}
}
fn value(self) -> u32 {
self.first.unwrap() * 10 + self.last.unwrap_or(self.first.unwrap())
}
}
let out: u32 = input
.lines()
.map(|line| {
line.chars().fold(FirstLast::new(), |mut val, char| {
if let Some(digit) = char.to_digit(10) {
val.record(digit)
}
val
})
})
.map(FirstLast::value)
.sum();
println!("{:?}", out);
}