Advent 2023 Day 1
This commit is contained in:
parent
e8126364c4
commit
e55fda8da2
4 changed files with 1141 additions and 1 deletions
25
advent_of_code_2023/day1/main1.rs
Normal file
25
advent_of_code_2023/day1/main1.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use std::fs::read_to_string;
|
||||
|
||||
fn main() {
|
||||
let mut calibration = 0;
|
||||
|
||||
for line in read_to_string("input.txt").unwrap().lines() {
|
||||
let mut first = 0;
|
||||
let mut last = 0;
|
||||
let mut set_first = false;
|
||||
|
||||
for char in line.chars() {
|
||||
if char.is_ascii_digit() {
|
||||
if !set_first {
|
||||
first = char as i32 - '0' as i32;
|
||||
set_first = true;
|
||||
}
|
||||
last = char as i32 - '0' as i32;
|
||||
}
|
||||
}
|
||||
|
||||
calibration += 10 * first + last;
|
||||
}
|
||||
|
||||
println!("{}", calibration);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue