added day 1-1
This commit is contained in:
parent
b84b42f278
commit
97bec285ce
|
@ -1 +1,23 @@
|
||||||
const INPUTS: [&'static str; 2] = [include_str!("./sample.txt"), include_str!("./input.txt")];
|
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
1000
src/day1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
4
src/day1/sample.txt
Normal file
4
src/day1/sample.txt
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
1abc2
|
||||||
|
pqr3stu8vwx
|
||||||
|
a1b2c3d4e5f
|
||||||
|
treb7uchet
|
Loading…
Reference in New Issue
Block a user