summaryrefslogtreecommitdiff
path: root/day_05.zig
diff options
context:
space:
mode:
authorChristian Segundo2022-12-05 23:17:47 +0100
committerChristian Segundo2022-12-05 23:17:47 +0100
commit7dd0e13d775e65b3071cd14136d9da7888b48021 (patch)
treeb2633fb4a5a7f2f44e4b7e5ece8e478efdc71f5e /day_05.zig
parentf4b6e0d4de7cd7f904c8016e68ff0f17900259b8 (diff)
downloadadvent-of-zig-2022-7dd0e13d775e65b3071cd14136d9da7888b48021.tar.gz
remove clutter
Diffstat (limited to 'day_05.zig')
-rw-r--r--day_05.zig14
1 files changed, 4 insertions, 10 deletions
diff --git a/day_05.zig b/day_05.zig
index 300fb1e..4550d76 100644
--- a/day_05.zig
+++ b/day_05.zig
@@ -18,11 +18,8 @@ pub fn puzzle_1(allocator: std.mem.Allocator, input: []const u8) !Result {
var data = try parse_input(allocator, input);
defer data.deinit(allocator);
- for (data.Commands) |command| {
- var command_crates = command.Crates;
-
- while (command_crates > 0) : (command_crates -= 1) {
- if (command_crates == 0) break;
+ for (data.Commands) |*command| {
+ while (command.Crates > 0) : (command.Crates -= 1) {
const tmp = data.Crates[command.From][len(data.Crates[command.From]) - 1];
data.Crates[command.From][len(data.Crates[command.From]) - 1] = 0;
data.Crates[command.To][len(data.Crates[command.To])] = tmp;
@@ -36,15 +33,12 @@ pub fn puzzle_2(allocator: std.mem.Allocator, input: []const u8) !Result {
var data = try parse_input(allocator, input);
defer data.deinit(allocator);
- for (data.Commands) |command| {
- var command_crates = command.Crates;
-
+ for (data.Commands) |*command| {
const crate_stack = blk: {
var r = std.mem.zeroes([MAX_HEIGHT]u8);
var idx: usize = 0;
- while (command_crates > 0) : (command_crates -= 1) {
- if (command_crates == 0) break;
+ while (command.Crates > 0) : (command.Crates -= 1) {
r[idx] = data.Crates[command.From][len(data.Crates[command.From]) - 1];
data.Crates[command.From][len(data.Crates[command.From]) - 1] = 0;
idx += 1;