Skip to content

Commit e30366b

Browse files
committed
Document year 2015 day 1-2
1 parent 6340cc8 commit e30366b

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub mod year2021 {
7575
pub mod day25;
7676
}
7777

78-
/// # Try to enjoy a well deserved vacation, what could go wrong?
78+
/// # What could go wrong trying to enjoy a well deserved vacation?
7979
pub mod year2020 {
8080
pub mod day01;
8181
pub mod day02;

src/year2020/day01.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
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.
115
use crate::util::parse::*;
216
use std::cmp::Ordering::*;
317

src/year2020/day02.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
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
112
use crate::util::iter::*;
213
use crate::util::parse::*;
314

0 commit comments

Comments
 (0)