This commit is contained in:
dobiadi
2025-12-01 18:45:43 +01:00
commit 123c96223f
3 changed files with 4411 additions and 0 deletions

4352
day1/zig/input.txt Normal file
View File

File diff suppressed because it is too large Load Diff

49
day1/zig/main.zig Normal file
View File

@@ -0,0 +1,49 @@
const std = @import("std");
const Instruction = enum {
L,
R,
};
const MAGIC_NUMBER = 100;
pub fn main() !void {
var stdin_buffer: [1024]u8 = undefined;
var stdin_reader = std.fs.File.stdin().reader(&stdin_buffer);
const stdin = &stdin_reader.interface;
var current: i32 = 50;
var task1: u32 = 0;
var task2: u32 = 0;
while (try stdin.takeDelimiter('\n')) |line| {
var num = try std.fmt.parseInt(i32, line[1..], 10);
switch (line[0]) {
'L' => {
while (num > 0) : (num -= 1) {
current = @mod(current - 1, MAGIC_NUMBER);
if (current == 0) {
task2 += 1;
}
}
},
'R' => {
while (num > 0) : (num -= 1) {
current = @mod(current + 1, MAGIC_NUMBER);
if (current == 0) {
task2 += 1;
}
}
},
else => unreachable,
}
if (current == 0) {
task1 += 1;
}
}
std.debug.print("{d}\n", .{task1});
std.debug.print("{d}\n", .{task2});
}

10
day1/zig/sample.txt Normal file
View File

@@ -0,0 +1,10 @@
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82