Finish day04, part 2
This commit is contained in:
parent
268b709c07
commit
fe3b71908e
1 changed files with 58 additions and 27 deletions
|
|
@ -3,12 +3,33 @@ const std = @import("std");
|
|||
pub const title = "Day 04: Printing Department";
|
||||
|
||||
pub fn run(_: std.mem.Allocator) !void {
|
||||
const input = @embedFile("./input/day04.txt");
|
||||
var lines = std.mem.tokenizeScalar(u8, input, '\n');
|
||||
const initial_input = @embedFile("./input/day04.txt");
|
||||
//const initial_input =
|
||||
// \\..@@.@@@@.
|
||||
// \\@@@.@.@.@@
|
||||
// \\@@@@@.@.@@
|
||||
// \\@.@@@@..@.
|
||||
// \\@@.@@@@.@@
|
||||
// \\.@@@@@@@.@
|
||||
// \\.@.@.@.@@@
|
||||
// \\@.@@@.@@@@
|
||||
// \\.@@@@@@@@.
|
||||
// \\@.@.@@@.@.
|
||||
// ;
|
||||
|
||||
const input: []u8 = @constCast(initial_input);
|
||||
|
||||
var accumulator: u32 = 0;
|
||||
|
||||
while (true) {
|
||||
std.debug.print("{s}\n", .{input});
|
||||
|
||||
var rolls_removed: u32 = 0;
|
||||
|
||||
var lines = std.mem.tokenizeScalar(u8, input, '\n');
|
||||
|
||||
var previous_line: ?[]const u8 = null;
|
||||
var line_index: usize = 0;
|
||||
while (lines.next()) |line| {
|
||||
const next_line = lines.peek();
|
||||
|
||||
|
|
@ -36,11 +57,21 @@ pub fn run(_: std.mem.Allocator) !void {
|
|||
}
|
||||
|
||||
if (rolls < 4) {
|
||||
accumulator += 1;
|
||||
input[(line_index * (line.len + 1)) + i] = 'x';
|
||||
rolls_removed += 1;
|
||||
}
|
||||
}
|
||||
|
||||
previous_line = line;
|
||||
line_index += 1;
|
||||
}
|
||||
|
||||
std.debug.print("removed {d} rolls\n", .{rolls_removed});
|
||||
if (rolls_removed > 0) {
|
||||
accumulator += rolls_removed;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var buffer: [8]u8 = undefined;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue