File tree 3 files changed +26
-1
lines changed
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ pub mod year2021 {
75
75
pub mod day25;
76
76
}
77
77
78
- /// # Try to enjoy a well deserved vacation, what could go wrong ?
78
+ /// # What could go wrong trying to enjoy a well deserved vacation?
79
79
pub mod year2020 {
80
80
pub mod day01;
81
81
pub mod day02;
Original file line number Diff line number Diff line change
1
+ //! # Report Repair
2
+ //!
3
+ //! The straightforward approach is to compare every possible pair of elements for part 1 and
4
+ //! every possible triple for part 2. This would have `O(n²)` and `O(n³)`time complexity respectively.
5
+ //!
6
+ //! We can do better with `O(n)` complexity for part 1 and `O(n²)` for part 2, with an shared
7
+ //! upfront cost of `O(logn)`.
8
+ //!
9
+ //! First sort the slice in ascending order. Then maintain two pointers starting at the beginning
10
+ //! and end of the slice. If the sum if greater then decrement the end pointer. If the sum is less
11
+ //! decrement the end pointer. If equal then return the product of the pair.
12
+ //!
13
+ //! Part 2 reuses the pair finding logic, finding the third element by stepping through the slice
14
+ //! one by one and adjusting the target total.
1
15
use crate :: util:: parse:: * ;
2
16
use std:: cmp:: Ordering :: * ;
3
17
Original file line number Diff line number Diff line change
1
+ //! # Password Philosophy
2
+ //!
3
+ //! Parsing the rules upfront allows both part 1 and part 2 to be solved in a straightforward manner.
4
+ //!
5
+ //! There's no need to first convert the input into lines since we know that each rule has 4 parts.
6
+ //! Instead we use the [`split`] method with a slice of delimeters to break the input into
7
+ //! an `Iterator` of tokens, then use our utility [`chunk`] method to group the tokens into an
8
+ //! array of size 4.
9
+ //!
10
+ //! [`split`]: slice::split
11
+ //! [`chunk`]: crate::util::iter
1
12
use crate :: util:: iter:: * ;
2
13
use crate :: util:: parse:: * ;
3
14
You can’t perform that action at this time.
0 commit comments