File tree 15 files changed +28
-26
lines changed
15 files changed +28
-26
lines changed Original file line number Diff line number Diff line change 17
17
//! ```
18
18
//!
19
19
//! A convenience [`parse`] method creates a `Grid` directly from a 2 dimenionsal set of
20
- //! ASCII characters, a common occurence in AoC inputs. The [`default_copy`] function creates a
21
- //! grid of the same size, that can be used for in BFS algorithms for tracking visited location
22
- //! or for tracking cost in Djikstra.
20
+ //! ASCII characters, a common occurence in Advent of Code inputs. The [`default_copy`] function
21
+ //! creates a grid of the same size, that can be used for in BFS algorithms for tracking visited
22
+ //! location or for tracking cost in Djikstra.
23
23
//!
24
24
//! [`Point`]: crate::util::point
25
25
//! [`parse`]: Grid::parse
Original file line number Diff line number Diff line change 1
1
//! Extracts and parses signed and unsigned integers from surrounding text and whitespace.
2
2
//!
3
- //! A common pattern in AoC is to parse and return `123`, `456` and `789` from input resembling:
3
+ //! A common pattern in Advent of Code is to parse and return `123`, `456` and `789` from input
4
+ //! resembling:
4
5
//!
5
6
//! ```none
6
7
//! Lorem ipsum 123 dolor 456 sit 789 amet
7
8
//! ```
8
9
//!
9
10
//! This module provides two [`&str`] extension methods [`iter_signed`] and [`iter_unsigned`]. The
10
- //! reason for the separate methods is that some AoC inputs contains the `-` character as a
11
- //! delimeter and this would cause numbers to be incorrectly parsed as negative.
11
+ //! reason for the separate methods is that some Advent of Code inputs contains the `-` character
12
+ //! as a delimeter and this would cause numbers to be incorrectly parsed as negative.
12
13
//!
13
14
//! [`iter_unsigned`]: ParseOps::iter_unsigned
14
15
//! [`iter_signed`]: ParseOps::iter_signed
Original file line number Diff line number Diff line change 1
1
//! Comprehensive 2 dimensional point implementation. This class is designed to work together
2
2
//! with the [`Grid`] class.
3
3
//!
4
- //! A common theme in AoC is operations in 2 dimensions. This module provides a [`Point`] struct
5
- //! along with implementations of several of the [`std::ops`] traits to support
4
+ //! A common theme in Advent of Code is operations in 2 dimensions. This module provides a
5
+ //! [`Point`] struct along with implementations of several of the [`std::ops`] traits to support
6
6
//! operator overloading, that allows shorthand expressions such as:
7
7
//!
8
8
//! ```
Original file line number Diff line number Diff line change 1
1
//! # Elves Look, Elves Say
2
2
//!
3
3
//! There is a trick to solve this problem in constant time and space. While this is not possible
4
- //! for any arbitrary sequence, in AoC *we only need to solve for our given input*.
4
+ //! for any arbitrary sequence, in Advent of Code *we only need to solve for our given input*.
5
5
//!
6
6
//! Examining the input shows that it consists of one of Conway's
7
7
//! [atomic elements](https://en.wikipedia.org/wiki/Look-and-say_sequence#Cosmological_decay).
Original file line number Diff line number Diff line change 1
1
//! # Toboggan Trajectory
2
2
//!
3
- //! Two dimensional grids of ASCII characters are a common AoC theme, so we use our utility
4
- //! [`Grid`] class to parse the data.
3
+ //! Two dimensional grids of ASCII characters are a common Advent of Code theme,
4
+ //! so we use our utility [`Grid`] class to parse the data.
5
5
//!
6
6
//! [`Grid`]: crate::util::grid
7
7
use crate :: util:: grid:: * ;
Original file line number Diff line number Diff line change 49
49
//!
50
50
//! For example `42 42 31` or `42 42 42 31` or `42 42 42 31 31` matches but *not* `42 42 31 31`.
51
51
//!
52
- //! Since we don't need to handle the general input case (a common pattern in AoC ) we can
52
+ //! Since we don't need to handle the general input case (a common pattern in Advent of Code ) we can
53
53
//! implement this rule directly in code.
54
54
use crate :: util:: parse:: * ;
55
55
use Rule :: * ;
Original file line number Diff line number Diff line change 5
5
//! circular buffer. Why use our own implementation when there is a perfectly good [`VecDeque`]
6
6
//! already available? The answer is speed. As there are at most fifty cards in the pack, the Deck
7
7
//! can use a fix sized stack allocated array, avoiding the expensive heap allocations that
8
- //! VecDeque must use.
8
+ //! [` VecDeque`] must use.
9
9
//!
10
10
//! `Deck` also keeps the score up to date as cards are added and removed, as this comes in useful
11
11
//! during part two. To update the score when a card is removed we subtract the card's value
Original file line number Diff line number Diff line change 1
1
//! # Dive!
2
2
//!
3
3
//! Both part 1 and part 2 rely on the [`fold`] method. This method comes in useful for a lot
4
- //! of AoC problems so is handy to know about. The input is parsed into a tuple enum [`Sub`] for
5
- //! convenience.
4
+ //! of Advent of Code problems so is handy to know about. The input is parsed into a tuple enum
5
+ //! [`Sub`] for convenience.
6
6
//!
7
7
//! [`fold`]: Iterator::fold
8
8
use crate :: util:: iter:: * ;
Original file line number Diff line number Diff line change 7
7
//! such as a [`VecDeque`].
8
8
//!
9
9
//! This solution uses a DFS approach as it's faster and Rust's stack size limit seems enough
10
- //! to accommodate the maximum basin size. 2 dimensional grids are common in AoC problems so we
11
- //! use our utility [`Grid`] and [`Point`] modules.
10
+ //! to accommodate the maximum basin size. 2 dimensional grids are common in Advent of Code
11
+ //! problems so we use our utility [`Grid`] and [`Point`] modules.
12
12
//!
13
13
//! [`VecDeque`]: std::collections::VecDeque
14
14
//! [`Grid`]: crate::util::grid
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ type Pairs = [u32; 4];
24
24
/// Parse each line into 4 integers.
25
25
///
26
26
/// Notes:
27
- /// * Extracting integers from redundant text is a very common theme in AoC that
27
+ /// * Extracting integers from redundant text is a very common theme in Advent of Code that
28
28
/// the [`iter_unsigned`] method handles.
29
29
///
30
30
/// [`iter_unsigned`]: ParseOps::iter_unsigned
Original file line number Diff line number Diff line change 15
15
///
16
16
/// Notes:
17
17
/// * We need to [`trim`] to remove the trailing newline character
18
- /// * AoC input is always ASCII characters, so casting to an `u8` slice is acceptable.
18
+ /// * Advent of Code input is always ASCII characters, so casting to an `u8` slice is acceptable.
19
19
///
20
20
/// [`trim`]: str::trim
21
21
pub fn parse ( input : & str ) -> Vec < usize > {
Original file line number Diff line number Diff line change 1
1
//! # No Space Left On Device
2
2
//!
3
3
//! Some up-front analysis of the input data helps us develop an efficient solving algorithm (this
4
- //! is a regular theme in AoC !). Looking at the directory commands shows 2 key insights:
4
+ //! is a regular theme in Advent of Code !). Looking at the directory commands shows 2 key insights:
5
5
//! * We never return to a previously visited directory
6
6
//! * Directory traversal is only up or down in steps of one.
7
7
//!
Original file line number Diff line number Diff line change 1
1
//! # Rope Bridge
2
2
//!
3
- //! This solution relies on the [`Point`] utility class. Two dimensional problems are common in AoC,
4
- //! so having a decent `Point` (or `Coord` or `Pos`) class in your back pocket is handy.
3
+ //! This solution relies on the [`Point`] utility class. Two dimensional problems are common in
4
+ //! Advent of Code, so having a decent `Point` (or `Coord` or `Pos`) class in your back pocket
5
+ //! is handy.
5
6
use crate :: util:: iter:: * ;
6
7
use crate :: util:: parse:: * ;
7
8
use crate :: util:: point:: * ;
Original file line number Diff line number Diff line change 1
1
//! # Monkey in the Middle
2
2
//!
3
- //! This problem is the combination of 2 AoC classics, extracting numbers from a wall of
4
- //! flavor text and modular arithmetic. For the first problem, our utility [`iter_unsigned`] method
5
- //! comes in handy.
3
+ //! This problem is the combination of two Advent of Code classics, extracting numbers from a wall
4
+ //! of flavor text and modular arithmetic. For the first problem, our utility [`iter_unsigned`]
5
+ //! method comes in handy.
6
6
//!
7
7
//! For the second problem, the key insight for part 2 is that
8
8
//! `a % m` is the same as `(a % n) % m` if `m` is a factor of `n`.
Original file line number Diff line number Diff line change 2
2
//!
3
3
//! Pretty much textbook implementation of a BFS (Breadth First Search). If you're not familar with
4
4
//! BFS, [this blog post is a great introduction](https://www.redblobgames.com/pathfinding/a-star/introduction.html)
5
- //! to the algorithm, plus some others that come in handy for AoC .
5
+ //! to the algorithm, plus some others that come in handy for Advent of Code .
6
6
//!
7
7
//! Implementation notes:
8
8
//! * A [`VecDeque`] of [`Point`] is used to store the frontier as it gives better performance
You can’t perform that action at this time.
0 commit comments