|
|
@ -169,18 +169,17 @@ fn getNextTasks(board: []const []const u8, task: Task) NextTasks { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn solveLines(lines: [][]u8) usize { |
|
|
|
fn solveLines(lines: [][]u8) usize { |
|
|
|
var total_max: u32 = 0; |
|
|
|
|
|
|
|
for (lines) |line| { |
|
|
|
for (lines) |line| { |
|
|
|
for (line) |*char| { |
|
|
|
for (line) |*char| { |
|
|
|
char.* = char.* - '0'; |
|
|
|
char.* = char.* - '0'; |
|
|
|
total_max += char.*; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const x_max = @as(u8, @intCast(lines.len - 1)); |
|
|
|
const x_max = @as(u8, @intCast(lines.len - 1)); |
|
|
|
const y_max = @as(u8, @intCast(lines[x_max].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(); |
|
|
|
var tasks = RingQueue(Task, usize, 1_024_576).init(); |
|
|
|
tasks.add(.{ |
|
|
|
tasks.add(.{ |
|
|
|
.current_heat = lines[x_max][y_max], |
|
|
|
.current_heat = lines[x_max][y_max], |
|
|
@ -208,7 +207,7 @@ fn solveLines(lines: [][]u8) usize { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (false) { |
|
|
|
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.len) |x| { |
|
|
|
for (0..lines[x].len) |y| { |
|
|
|
for (0..lines[x].len) |y| { |
|
|
|
std.debug.print("{d}/{d} ", .{ results[x][y].get(.Horizontal), results[x][y].get(.Vertical) }); |
|
|
|
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 { |
|
|
|
pub fn solveAll(reader: anytype) !usize { |
|
|
|