pub struct GraphPathCounter {
    pub cells: RefCell<HashMap<Coord, usize>>,
    /* private fields */
}
Expand description

Stores a representation of the underlying graph, tracking how many paths have reached each node at current time step self.step.

Calling next steps the KitchenFloor steps the graph representation forward by: a) introducing any new nodes to the graph which haven’t don’t already exist from previous steps b) iterating every node in the graph and setting its new value to the be the sum of the values in the surrounding nodes from the previous step (but not counting any contribution from the origin, because any paths which reached this on the previous step would have terminated there).

Fields§

§cells: RefCell<HashMap<Coord, usize>>

Tracks the total number of paths which can arrive at a given coord by a certain time step.

Implementations§

source§

impl GraphPathCounter

source

pub fn new() -> Self

Create a new graph counter.

source

pub fn next(&mut self)

Step the internal graph representation forward.

In summary, this function does works by: a) introducing any new nodes to the graph which haven’t don’t already exist from previous steps b) iterating every node in the graph and setting its new value to the be the sum of the values in the surrounding nodes from the previous step (but not counting any contribution from the origin, because any paths which reached this on the previous step would have terminated there).

source

pub fn calculate(&mut self, steps: u32)

Run the analysis for a given number of steps.

This function tracks how many paths return to the origin (0, 0) in total across all the steps. We need to be careful to upscale each such number by a factor of $3^k$ where $k$ is the number of remaining steps. This accounts for the fact that we stop counting the paths once they have returned home. If we kept counting them each one would diverge into $3^k$ paths over the remaining $k$ steps. We need to apportion the probability mass correctly in order to divide by $3^{20}$ total paths at the end.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V