View on GitHub

advent-of-code-2022

Readable Advent of Code 2022 algorithms and solutions in C language

Day 5: Supply Stacks

Let $\ell$ be a list of tuples where for all $e\in\ell$, we have $e=(a,b,c)$ for $a,b\in\lbrace 0,\dots,n\rbrace$ and $c\in\mathbb{N}$.

Part A

Let $(S_0,\dots,S_n)$ be a list of $n$ stacks.

For $(a,b,c)\in\ell$:

Let $m\leftarrow()$.

For $S\in(S_0,\dots,S_n)$, append top of $S$ to $m$.

Return $m$.

Part B

Let $(k_0,\dots,k_n)$ be a list of $n$ lists.

For $(a,b,c)\in\ell$:

Let $m\leftarrow()$.

For $k\in(k_0,\dots,k_n)$, append last element of $k$ to $m$.

Return $m$.