From 1d56beeab991e3dbdbb64b904067dd7081904cb7 Mon Sep 17 00:00:00 2001 From: Inga Date: Tue, 26 Dec 2023 19:11:47 +0000 Subject: [PATCH] day 17, part 1 (fixed solution) --- day17-easy/src/main.zig | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/day17-easy/src/main.zig b/day17-easy/src/main.zig index 95bf12a..b832625 100644 --- a/day17-easy/src/main.zig +++ b/day17-easy/src/main.zig @@ -169,18 +169,17 @@ fn getNextTasks(board: []const []const u8, task: Task) NextTasks { } fn solveLines(lines: [][]u8) usize { - var total_max: u32 = 0; for (lines) |line| { for (line) |*char| { char.* = char.* - '0'; - total_max += char.*; } } const x_max = @as(u8, @intCast(lines.len - 1)); const y_max = @as(u8, @intCast(lines[x_max].len - 1)); + const max_value: u16 = @as(u16, 18) * @max(x_max, y_max) + lines[x_max][y_max]; - var results: Results = [_][150]ResultsByDirection{[_]ResultsByDirection{ResultsByDirection.initFill(total_max)} ** 150} ** 150; + var results: Results = [_][150]ResultsByDirection{[_]ResultsByDirection{ResultsByDirection.initFill(max_value)} ** 150} ** 150; var tasks = RingQueue(Task, usize, 1_024_576).init(); tasks.add(.{ .current_heat = lines[x_max][y_max], @@ -208,7 +207,7 @@ fn solveLines(lines: [][]u8) usize { } if (false) { - std.debug.print("Total tasks done: {d}\n", .{i}); + //std.debug.print("Total tasks done: {d}\n", .{i}); for (0..lines.len) |x| { for (0..lines[x].len) |y| { std.debug.print("{d}/{d} ", .{ results[x][y].get(.Horizontal), results[x][y].get(.Vertical) }); @@ -217,7 +216,7 @@ fn solveLines(lines: [][]u8) usize { } } - return results[0][0].get(.Vertical) - lines[0][0]; + return @min(results[0][0].get(.Vertical), results[0][0].get(.Horizontal)) - lines[0][0]; } pub fn solveAll(reader: anytype) !usize {