Compare commits
No commits in common. "fe3b71908e110dbd758fa3cf05454ab9a5d0c09c" and "7a0c4751ebd87f9a4e1d331a2b663bd62b0bb75b" have entirely different histories.
fe3b71908e
...
7a0c4751eb
1 changed files with 28 additions and 59 deletions
|
|
@ -1,35 +1,14 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub const title = "Day 04: Printing Department";
|
pub const title = "Day 04";
|
||||||
|
|
||||||
pub fn run(_: std.mem.Allocator) !void {
|
pub fn run(_: std.mem.Allocator) !void {
|
||||||
const initial_input = @embedFile("./input/day04.txt");
|
const input = @embedFile("./input/day04.txt");
|
||||||
//const initial_input =
|
var lines = std.mem.tokenizeScalar(u8, input, '\n');
|
||||||
// \\..@@.@@@@.
|
|
||||||
// \\@@@.@.@.@@
|
|
||||||
// \\@@@@@.@.@@
|
|
||||||
// \\@.@@@@..@.
|
|
||||||
// \\@@.@@@@.@@
|
|
||||||
// \\.@@@@@@@.@
|
|
||||||
// \\.@.@.@.@@@
|
|
||||||
// \\@.@@@.@@@@
|
|
||||||
// \\.@@@@@@@@.
|
|
||||||
// \\@.@.@@@.@.
|
|
||||||
// ;
|
|
||||||
|
|
||||||
const input: []u8 = @constCast(initial_input);
|
|
||||||
|
|
||||||
var accumulator: u32 = 0;
|
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 previous_line: ?[]const u8 = null;
|
||||||
var line_index: usize = 0;
|
|
||||||
while (lines.next()) |line| {
|
while (lines.next()) |line| {
|
||||||
const next_line = lines.peek();
|
const next_line = lines.peek();
|
||||||
|
|
||||||
|
|
@ -57,21 +36,11 @@ pub fn run(_: std.mem.Allocator) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rolls < 4) {
|
if (rolls < 4) {
|
||||||
input[(line_index * (line.len + 1)) + i] = 'x';
|
accumulator += 1;
|
||||||
rolls_removed += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
previous_line = line;
|
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;
|
var buffer: [8]u8 = undefined;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue