This commit is contained in:
Braiden Gent
2025-12-04 11:32:42 -08:00
parent 312b33ec9c
commit 803386e5ee

View File

@@ -1,11 +1,11 @@
const std = @import("std");
const debug = std.debug;
pub fn main() !void {
var location: i32 = 50;
var res: i32 = 0;
var res2: i32 = 0;
var file = try std.fs.cwd().openFile("/home/eng-bgent/adventOfCode/25/1/input.txt", .{});
var file = try std.fs.cwd().openFile("input.txt", .{});
defer file.close();
var buf: [64]u8 = undefined;
@@ -15,28 +15,30 @@ pub fn main() !void {
var stdout = std.fs.File.stdout().writer(&stdout_buf);
while (try fr.interface.takeDelimiter('\n')) |line| {
try stdout.interface.print("{s} {s}\n", .{line, line[1..]});
var val: i32 = try std.fmt.parseInt(i32, line[1..], 10);
const neg: bool = if(line[0] == 'L') true else false;
const neg: bool = if (line[0] == 'L') true else false;
const was_zero: bool = if (location == 0) true else false;
res2 += @divFloor(val, 100);
val = @rem(val, 100);
try stdout.interface.print("{}\n", .{val});
if (neg) {
val *= -1;
}
if (neg) val *= -1;
location += val;
if (location < 0)
{
location = 100 + location;
if (location < 0) {
location += 100;
if (!was_zero) res2 += 1;
} else if (location > 99) {
location -= 100;
if (!was_zero) res2 += 1;
} else if (location == 0) {
res2 += 1;
}
if (location == 0) {
res += 1;
}
if (location == 0) res += 1;
try stdout.interface.print("{d} {}\n", .{val, neg});
try stdout.interface.flush();
}
try stdout.interface.print("{d}\n", .{res});
try stdout.interface.print("{} {}\n", .{ res, res2 });
try stdout.interface.flush();
}