# AoC 2026: Day 5

**URL:** <https://ziggit.dev/t/aoc-2026-day-5/18714>\
**Category:** Challenge\
**Tags:** advent-of-code\
**Created:** [December 5, 2026, 5:12am UTC](https://ziggit.dev/t/aoc-2026-day-5/18714 "2026-12-05T05:12:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Calder-Ty](https://ziggit.dev/user_avatar/ziggit.dev/calder-ty/32/10237_2.png) [@Calder-Ty](https://ziggit.dev/u/Calder-Ty)\
**Post date:** [December 5, 2026, 5:12am UTC](https://ziggit.dev/t/aoc-2026-day-5/18714/1 "2026-12-05T05:12:09Z")

</div>

Main thread for Day 5 of the 2026 advent of code. Feel free to discuss the challenge and ask questions. If particular discussions become large, we can break them off into new threads.

Notice that Advent of Code has changed it’s schedule and there will only be 12 days of puzzles this year.

Some Rules:

1. Please try to keep spoilers within spoiler tags. This is done by typing [spoiler]text to be blurred[\spoiler]. If you have longer sections you can also use the [details=“Title”] tags.
2. Have Fun

[Day 5 Challenge](https://adventofcode.com/2026/day/5)

Templates:

- [GitHub - evaleek/advent-of-code-template: Advent of Code template for Zig solutions · GitHub](https://github.com/evaleek/advent-of-code-template)

Resources:

- [Advent of Code in Zig | Loris Cro’s Blog](https://kristoff.it/blog/advent-of-code-zig): Advice and Tips on How to do AoC with Zig
- [https://zigbin.io](https://zigbin.io/): A website for sharing zig code
- [Documentation - The Zig Programming Language](https://ziglang.org/documentation/master/) : Zig Language Reference
- [Zig Documentation](https://ziglang.org/documentation/master/std/): Zig Standard Library Docs
- [Docs](https://ziggit.dev/docs) : Community Created Docs and Tutorials
- Private Leaderboard: 1910115-f465b6d3

---

<div class="post-metadata">

**Author:** ![truly-not-taken](https://ziggit.dev/user_avatar/ziggit.dev/truly-not-taken/32/6205_2.png) [@truly-not-taken](https://ziggit.dev/u/truly-not-taken)\
**Post date:** [December 5, 2026, 7:47am UTC](https://ziggit.dev/t/aoc-2026-day-5/18714/2 "2026-12-05T07:47:26Z")

</div>

~~Parser: 83 lines.  
State machine: 51 lines.  
Part 1 loops: 25 lines.  
Part 2 loop: 14 lines.  
It was a chore. I am exhausted. I do not know why Eric likes this kind of puzzles.~~ I guess it would be much easier in some scripting language with regexps.

I thought I would need nested loops for part 2. Apparently `numbers.append()` inside the loop over `numbers` was enough to find all the numbers.

Edit: I revisited it and cleaned up some mess. Now it feels much nicer.

I do not know why everyone seem to always use hashmaps. The number can not go higher than 9999. An array is enough.

> **part 1 and part 2**
>
> ```zig
> var sum: u32 = 0;
> var numbers: [10000]bool = @splat(false);
> numbers[0] = true;
> var list: std.ArrayList(u32) = .empty;
> defer list.deinit(gpa);
> try list.append(gpa, 0);
> for (0..3) |_| {
> const olds = try list.toOwnedSlice(gpa);
> defer gpa.free(olds);
> for (olds) |old| {
> for (buttons[0..len]) |b| {
> const new = b.push(old);
> if (!numbers[new]) {
> numbers[new] = true;
> sum += new;
> try list.append(gpa, new);
> }
> }
> }
> }
> try queue.putOne(io, .m(p, .part1, sum));
> while (list.pop()) |screen| {
> for (buttons[0..len]) |button| {
> const number = button.push(screen);
> if (number > 9999) continue;
> if (!numbers[number]) {
> numbers[number] = true;
> sum += number;
> try list.append(gpa, number);
> }
> }
> }
> try queue.putOne(io, .m(p, .part2, sum));
> 
> ```

---

<div class="post-metadata">

**Author:** ![SpinTensor](https://ziggit.dev/user_avatar/ziggit.dev/spintensor/32/2942_2.png) [@SpinTensor](https://ziggit.dev/u/SpinTensor)\
**Post date:** [December 5, 2026, 8:34am UTC](https://ziggit.dev/t/aoc-2026-day-5/18714/3 "2026-12-05T08:34:33Z")

</div>

That was fun.

After implementing the button functionality it was quite simple. Store obtained values in a hash map. Iterate over hashmap and sum.

> **part 1**
>
> ```zig
> pub fn pressThreeButtons(microwave: Microwave, values: *std.AutoHashMap(usize, usize), cook_time: usize, nbuttons: u8) void {
> if (nbuttons == 0) {
> for (microwave.buttons.items) |button| {
> const val = Microwave.pressButton(cook_time, button);
> values.put(
> val,
> val,
> ) catch {
> unreachable;
> };
> }
> } else {
> for (microwave.buttons.items) |button| {
> const curr_cook_time = Microwave.pressButton(
> cook_time,
> button,
> );
> pressThreeButtons(
> microwave,
> values,
> curr_cook_time,
> nbuttons - 1,
> );
> }
> }
> }
> 
> ```

> **part 2**
>
> ```zig
> pub fn pressButtons(microwave: Microwave, values: *std.AutoHashMap(usize, usize), cook_time: usize) void {
> for (microwave.buttons.items) |button| {
> const curr_cook_time = Microwave.pressButton(
> cook_time,
> button,
> );
> if (curr_cook_time <= 9999) {
> if (values.get(curr_cook_time) == null) {
> values.put(
> curr_cook_time,
> curr_cook_time,
> ) catch {
> unreachable;
> };
> pressButtons(microwave, values, curr_cook_time);
> }
> }
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![alonzo](https://ziggit.dev/user_avatar/ziggit.dev/alonzo/32/6006_2.png) [@alonzo](https://ziggit.dev/u/alonzo)\
**Post date:** [December 5, 2026, 5:11pm UTC](https://ziggit.dev/t/aoc-2026-day-5/18714/4 "2026-12-05T17:11:22Z")

</div>

hahaha, I knew right away this was going to be a dynamic programming problem 😈 . really fun problem today!
