|
|
@@ -1,5 +1,3 @@
|
|
|
-#[allow(dead_code)]
|
|
|
-
|
|
|
fn first_part(input: &str) -> usize {
|
|
|
let mut sum = 0;
|
|
|
for line in input.lines() {
|
|
|
@@ -15,7 +13,7 @@ fn first_part(input: &str) -> usize {
|
|
|
fn second_part(input: &str) -> usize {
|
|
|
let mut sum = 0;
|
|
|
for line in input.lines() {
|
|
|
- let (first, last) = find_first_last(&line);
|
|
|
+ let (first, last) = find_first_last(line);
|
|
|
let lineval = first * 10 + last;
|
|
|
sum += lineval;
|
|
|
}
|
|
|
@@ -70,21 +68,21 @@ mod day1_examples {
|
|
|
#[test]
|
|
|
fn example_1st_part() {
|
|
|
let example = "1abc2
|
|
|
- pqr3stu8vwx
|
|
|
- a1b2c3d4e5f
|
|
|
- treb7uchet";
|
|
|
+pqr3stu8vwx
|
|
|
+a1b2c3d4e5f
|
|
|
+treb7uchet";
|
|
|
assert_eq!(crate::first_part(example), 142);
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
fn example_2nd_part() {
|
|
|
let example = "two1nine
|
|
|
- eightwothree
|
|
|
- abcone2threexyz
|
|
|
- xtwone3four
|
|
|
- 4nineeightseven2
|
|
|
- zoneight234
|
|
|
- 7pqrstsixteen";
|
|
|
+eightwothree
|
|
|
+abcone2threexyz
|
|
|
+xtwone3four
|
|
|
+4nineeightseven2
|
|
|
+zoneight234
|
|
|
+7pqrstsixteen";
|
|
|
assert_eq!(crate::second_part(example), 281);
|
|
|
}
|
|
|
}
|