diff options
author | Christian Segundo | 2022-12-05 23:17:47 +0100 |
---|---|---|
committer | Christian Segundo | 2022-12-05 23:17:47 +0100 |
commit | 7dd0e13d775e65b3071cd14136d9da7888b48021 (patch) | |
tree | b2633fb4a5a7f2f44e4b7e5ece8e478efdc71f5e | |
parent | f4b6e0d4de7cd7f904c8016e68ff0f17900259b8 (diff) | |
download | advent-of-zig-2022-7dd0e13d775e65b3071cd14136d9da7888b48021.tar.gz |
remove clutter
-rw-r--r-- | day_05.zig | 14 |
1 files changed, 4 insertions, 10 deletions
@@ -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; |