View on GitHub

advent-of-code-2022

Readable Advent of Code 2022 algorithms and solutions in C language

Day 7: No Space Left on Device

Let $T=(V,E)$ be a directed tree.

Let $L\subseteq V$ denote the set of leaves in $T$. Let $w^\ast:L\to\mathbb{N}$.

Let $s\in V$.

Algorithm I.

Define $w_v$ for $v\in V$.

Let $S$ be an empty stack.

Let $D\leftarrow\emptyset$.

Push $s$ onto $S$.

While $S$ is not empty:

Return $w_v$ for $v\in V$.

Part A

Let $w_v$ for $v\in V$ be given by Algorithm I.

Let $V’=\lbrace v\,:\, v\in V,v\notin L, w_v\leq 100000\rbrace$.

Return $\sum_{v\in V’}{w_v}$.

Part B

Let $w_v$ for $v\in V$ be given by Algorithm I.

Let $V’=\lbrace v:v\in V,v\notin L,70000000-(w_s-w_v)\geq 30000000\rbrace$.

Return $\underset{v\in V’}{\min}(w_v)$.