added day 1-1

This commit is contained in:
Ishan Jain 2023-12-01 11:15:53 +05:30
parent b84b42f278
commit 97bec285ce
Signed by: ishan
GPG Key ID: 0506DB2A1CC75C27
3 changed files with 1026 additions and 0 deletions

View File

@ -1 +1,23 @@
const INPUTS: [&'static str; 2] = [include_str!("./sample.txt"), include_str!("./input.txt")];
fn main() {
for input in INPUTS.iter() {
let mut total = 0;
for line in input.split('\n') {
let first = line
.chars()
.find(|c| c.is_numeric())
.map_or(0, |x| 10 * x.to_digit(10).unwrap());
let last = line
.chars()
.rev()
.find(|c| c.is_numeric())
.map_or(0, |x| x.to_digit(10).unwrap());
total += (first + last);
}
println!("total = {}", total);
}
}

1000
src/day1/input.txt Normal file

File diff suppressed because it is too large Load Diff

4
src/day1/sample.txt Normal file
View File

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