diff --git a/README.md b/README.md index caad5fd..b6757a8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Thank you to [Eric Wastl](http://was.tl) for running this incredible yearly even ## [2023](https://adventofcode.com/2022) [![aoc_2023](https://github.com/Basicprogrammer10/advent-of-code/actions/workflows/aoc_2023.yml/badge.svg)](https://github.com/Basicprogrammer10/advent-of-code/actions/workflows/aoc_2023.yml) -- [Day 01:](aoc_2023/src/day_01.rs) +- [Day 01: Trebuchet?!](aoc_2023/src/day_01.rs) ## [2022](https://adventofcode.com/2022) [![aoc_2022](https://github.com/Basicprogrammer10/advent-of-code/actions/workflows/aoc_2022.yml/badge.svg)](https://github.com/Basicprogrammer10/advent-of-code/actions/workflows/aoc_2022.yml) diff --git a/aoc_2023/src/day_01.rs b/aoc_2023/src/day_01.rs index baa54a6..1ef7fdc 100644 --- a/aoc_2023/src/day_01.rs +++ b/aoc_2023/src/day_01.rs @@ -27,10 +27,7 @@ impl Solution for Day01 { let mut sum = 0; for line in input.lines() { let digits = digits(line); - let first = digits[0]; - let last = digits[digits.len() - 1]; - - sum += first * 10 + last; + sum += digits[0] * 10 + digits[1]; } sum.into() @@ -42,10 +39,8 @@ fn digits(i: &str) -> [u32; 2] { let mut last = 0; let mut digit = |c| { + first = first.or(Some(c)); last = c; - if first.is_none() { - first = Some(c); - } }; let chars = i.as_bytes();