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 {
|
||||
const input = @embedFile("./input/day11.txt");
|
||||
//const input =
|
||||
// \\aaa: you hhh
|
||||
// \\you: bbb ccc
|
||||
// \\bbb: ddd eee
|
||||
// \\ccc: ddd eee fff
|
||||
// \\ddd: ggg
|
||||
// \\eee: out
|
||||
// \\fff: out
|
||||
// \\svr: aaa bbb
|
||||
// \\aaa: fft
|
||||
// \\fft: ccc
|
||||
// \\bbb: tty
|
||||
// \\tty: ccc
|
||||
// \\ccc: ddd eee
|
||||
// \\ddd: hub
|
||||
// \\hub: fff
|
||||
// \\eee: dac
|
||||
// \\dac: fff
|
||||
// \\fff: ggg hhh
|
||||
// \\ggg: out
|
||||
// \\hhh: ccc fff iii
|
||||
// \\iii: out
|
||||
// \\hhh: out
|
||||
// ;
|
||||
|
||||
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;
|
||||
visitOutputs("you", devices, &paths_to_out);
|
||||
visitOutputs("svr", devices, &paths_to_out, false, false);
|
||||
|
||||
var buffer: [8]u8 = undefined;
|
||||
var stdout_writer = std.fs.File.stdout().writer(&buffer);
|
||||
|
|
@ -62,14 +65,26 @@ fn visitOutputs(
|
|||
start: []const u8,
|
||||
devices: std.StringHashMap([][]const u8),
|
||||
paths_to_out: *usize,
|
||||
visited_fft: bool,
|
||||
visited_dac: bool,
|
||||
) void {
|
||||
const device = devices.get(start);
|
||||
if (device) |outputs| {
|
||||
for (outputs) |output| {
|
||||
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 {
|
||||
visitOutputs(output, devices, paths_to_out);
|
||||
visitOutputs(output, devices, paths_to_out, visited_fft, visited_dac);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue