WIP: implement part 2
This commit is contained in:
parent
37b740f07a
commit
f85eda4e87
1 changed files with 27 additions and 12 deletions
|
|
@ -5,16 +5,19 @@ pub const title = "Day 11: Reactor";
|
||||||
pub fn run(allocator: std.mem.Allocator) !void {
|
pub fn run(allocator: std.mem.Allocator) !void {
|
||||||
const input = @embedFile("./input/day11.txt");
|
const input = @embedFile("./input/day11.txt");
|
||||||
//const input =
|
//const input =
|
||||||
// \\aaa: you hhh
|
// \\svr: aaa bbb
|
||||||
// \\you: bbb ccc
|
// \\aaa: fft
|
||||||
// \\bbb: ddd eee
|
// \\fft: ccc
|
||||||
// \\ccc: ddd eee fff
|
// \\bbb: tty
|
||||||
// \\ddd: ggg
|
// \\tty: ccc
|
||||||
// \\eee: out
|
// \\ccc: ddd eee
|
||||||
// \\fff: out
|
// \\ddd: hub
|
||||||
|
// \\hub: fff
|
||||||
|
// \\eee: dac
|
||||||
|
// \\dac: fff
|
||||||
|
// \\fff: ggg hhh
|
||||||
// \\ggg: out
|
// \\ggg: out
|
||||||
// \\hhh: ccc fff iii
|
// \\hhh: out
|
||||||
// \\iii: out
|
|
||||||
// ;
|
// ;
|
||||||
|
|
||||||
var lines = std.mem.tokenizeScalar(u8, input, '\n');
|
var lines = std.mem.tokenizeScalar(u8, input, '\n');
|
||||||
|
|
@ -47,7 +50,7 @@ pub fn run(allocator: std.mem.Allocator) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
var paths_to_out: usize = 0;
|
var paths_to_out: usize = 0;
|
||||||
visitOutputs("you", devices, &paths_to_out);
|
visitOutputs("svr", devices, &paths_to_out, false, false);
|
||||||
|
|
||||||
var buffer: [8]u8 = undefined;
|
var buffer: [8]u8 = undefined;
|
||||||
var stdout_writer = std.fs.File.stdout().writer(&buffer);
|
var stdout_writer = std.fs.File.stdout().writer(&buffer);
|
||||||
|
|
@ -62,14 +65,26 @@ fn visitOutputs(
|
||||||
start: []const u8,
|
start: []const u8,
|
||||||
devices: std.StringHashMap([][]const u8),
|
devices: std.StringHashMap([][]const u8),
|
||||||
paths_to_out: *usize,
|
paths_to_out: *usize,
|
||||||
|
visited_fft: bool,
|
||||||
|
visited_dac: bool,
|
||||||
) void {
|
) void {
|
||||||
const device = devices.get(start);
|
const device = devices.get(start);
|
||||||
if (device) |outputs| {
|
if (device) |outputs| {
|
||||||
for (outputs) |output| {
|
for (outputs) |output| {
|
||||||
if (std.mem.eql(u8, output, "out")) {
|
if (std.mem.eql(u8, output, "out")) {
|
||||||
paths_to_out.* += 1;
|
std.debug.print("found out! (fft = {any}, dac = {any})\n", .{visited_fft, visited_dac});
|
||||||
|
if (visited_fft and visited_dac) {
|
||||||
|
std.debug.print("visited fft and dac\n", .{});
|
||||||
|
paths_to_out.* += 1;
|
||||||
|
}
|
||||||
|
} else if (std.mem.eql(u8, output, "fft")) {
|
||||||
|
std.debug.print("found fft!\n", .{});
|
||||||
|
visitOutputs(output, devices, paths_to_out, true, visited_dac);
|
||||||
|
} else if (std.mem.eql(u8, output, "dac")) {
|
||||||
|
std.debug.print("found dac!\n", .{});
|
||||||
|
visitOutputs(output, devices, paths_to_out, visited_fft, true);
|
||||||
} else {
|
} else {
|
||||||
visitOutputs(output, devices, paths_to_out);
|
visitOutputs(output, devices, paths_to_out, visited_fft, visited_dac);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue