So im working on acent of code 2023 day 10 and im getting the following error:
src/2023/10.zig:69:42: error: unable to evaluate comptime expression
var n = *tiles[j - y];
~~^~~
src/2023/10.zig:69:40: note: operation is runtime due to this operand
var n = *tiles[j - y];
test "p1_1" {
...
var buffer: []const u8 =
\\.....
\\.S-7.
\\.|.|.
\\.L-J.
\\.....
;
const maze = try PipeMaze().init(allocator, buffer);
...
}
fn PipeMaze() type {
return struct {
...
fn init(allocator: std.mem.Allocator, buffer: []const u8) !Self {
// get dimensions
const x = std.mem.indexOf(u8, buffer, "\n") orelse unreachable;
const y = std.mem.count(u8, buffer, "\n") + 1;
...
// second pass
for (tiles, 0..) |tile, j| {
switch (tile.tile_type) {
TileType.ns => {
var n = *tiles[j - y]; // <= here
var s = *tiles[j + y];
...
}
...
}
...
}
...
}
}
comptime keyword is not used in this file so theres some implicit mechanism im unaware of. I can see how the test buffer and its dimensions could be comptime implicitly. That said, how can I let the compiler understand that I want the dimension y available during runtime?