Enum advent_of_code_2021::day_18::SnailfishNumber [−][src]
enum SnailfishNumber {
Num(u8),
Pair(Box<SnailfishNumber>, Box<SnailfishNumber>),
}Expand description
Represents a snailfish number as a binary tree
Variants
Num(u8)
Tuple Fields
0: u8Leaf node
Pair(Box<SnailfishNumber>, Box<SnailfishNumber>)
Branch node - branches need to be boxed so that it has a constant size
Implementations
Combine the two halves into a new SnailfishNumber::Pair, then repeatedly call
SnailfishNumber::check_depth, and SnailfishNumber::check_digits until neither change the tree.
Utility used by SnailfishNumber::check_depth to add one half of a pair to the next digit on the same side
of the tree. dir indicates which way this number is travelling, and num is the actual digit to be added.
Recursively walk the tree, if a Pair is found that is too deep, replace it with a leaf node with value 0,
then pass the two halves of the pair back up so that they can be added to the next leftmost and rightmost
leaves. As this is unwinding, assign the relevant side of the returned digit pair to the other half before
passing the rest back up. See also SnailfishNumber::with that helps with resolving the explosion.
Recursively hunt for a leaf that is >9, i.e. not a digit, and of one is found split it into a pair, each leaf of which is half the original (rounding halves down and up respectively so that they sum to the original). Returns true if an oversize leaf was found and split, false otherwise.
Trait Implementations
Parse a line of the input as a SnailfishNumber
This method tests for self and other values to be equal, and is used
by ==. Read more
This method tests for !=.
Auto Trait Implementations
impl RefUnwindSafe for SnailfishNumber
impl Send for SnailfishNumber
impl Sync for SnailfishNumber
impl Unpin for SnailfishNumber
impl UnwindSafe for SnailfishNumber
Blanket Implementations
Mutably borrows from an owned value. Read more
