Skip to content

Commit

Permalink
[2024] Added Day 24: Crossed Wires
Browse files Browse the repository at this point in the history
  • Loading branch information
ACSimon33 committed Dec 26, 2024
1 parent a385e75 commit 99bd63f
Show file tree
Hide file tree
Showing 12 changed files with 1,623 additions and 0 deletions.
758 changes: 758 additions & 0 deletions 2024/24/crossed_wires/adder.dot

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions 2024/24/crossed_wires/benchmarks/puzzle_benchmarks.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const std = @import("std");
const zbench = @import("zbench");
const crossed_wires = @import("crossed_wires");

const puzzle_input = @embedFile("puzzle_input");

// Benchmark of part 1
fn task_1(allocator: std.mem.Allocator) void {
_ = crossed_wires.simulate_gates(puzzle_input, allocator) catch {};
}

// Benchmark of part 2
fn task_2(allocator: std.mem.Allocator) void {
_ = crossed_wires.find_wrong_gates(puzzle_input, allocator) catch {};
}

pub fn main() !void {
const stdout = std.io.getStdOut().writer();
var bench = zbench.Benchmark.init(std.heap.page_allocator, .{});
defer bench.deinit();

try bench.add("Day 24 - Task 1", task_1, .{});
try bench.add("Day 24 - Task 2", task_2, .{});

try stdout.writeAll("\n");
try bench.run(stdout);
}
78 changes: 78 additions & 0 deletions 2024/24/crossed_wires/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const std = @import("std");

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// -------------------------- Solution module --------------------------- \\
const crossed_wires = b.addModule("crossed_wires", .{
.root_source_file = b.path("src/crossed_wires.zig"),
});

// -------------------------- Main executable --------------------------- \\
const crossed_wires_exe = b.addExecutable(.{
.name = "crossed_wires",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});

const yazap = b.dependency("yazap", .{});
crossed_wires_exe.root_module.addImport("yazap", yazap.module("yazap"));
crossed_wires_exe.root_module.addImport("crossed_wires", crossed_wires);
b.installArtifact(crossed_wires_exe);

const run_cmd = b.addRunArtifact(crossed_wires_exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}

const run_step = b.step("run", "Run Crossed Wires (day 24) app");
run_step.dependOn(&run_cmd.step);

// --------------------------- Example tests ---------------------------- \\
const crossed_wires_tests = b.addTest(.{
.name = "crossed_wires_tests",
.root_source_file = b.path("tests/example_tests.zig"),
.target = target,
.optimize = optimize,
});

crossed_wires_tests.root_module.addImport("crossed_wires", crossed_wires);
inline for (1..3) |i| {
const num_str = std.fmt.comptimePrint("{!}", .{i});
crossed_wires_tests.root_module.addAnonymousImport(
"example_input_" ++ num_str,
.{
.root_source_file = b.path("input/example_input_" ++ num_str ++ ".txt"),
},
);
}
b.installArtifact(crossed_wires_tests);

const test_step = b.step("test", "Run Crossed Wires (day 24) tests");
test_step.dependOn(&b.addRunArtifact(crossed_wires_tests).step);

// ------------------------- Puzzle benchmarks -------------------------- \\
const crossed_wires_benchmarks = b.addExecutable(.{
.name = "crossed_wires_benchmarks",
.root_source_file = b.path("benchmarks/puzzle_benchmarks.zig"),
.target = target,
.optimize = optimize,
});

const zbench = b.dependency("zbench", .{
.target = target,
.optimize = optimize,
});
crossed_wires_benchmarks.root_module.addImport("zbench", zbench.module("zbench"));
crossed_wires_benchmarks.root_module.addImport("crossed_wires", crossed_wires);
crossed_wires_benchmarks.root_module.addAnonymousImport("puzzle_input", .{
.root_source_file = b.path("input/puzzle_input.txt"),
});
b.installArtifact(crossed_wires_benchmarks);

const benchmark_step = b.step("benchmark", "Run Crossed Wires (day 24) benchmarks");
benchmark_step.dependOn(&b.addRunArtifact(crossed_wires_benchmarks).step);
}
23 changes: 23 additions & 0 deletions 2024/24/crossed_wires/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.{
.name = "crossed_wires",
.version = "0.1.0",
.minimum_zig_version = "0.13.0",
.dependencies = .{
.yazap = .{
.url = "git+https://github.com/prajwalch/yazap#c2e3122d5dd6192513ba590f229dbc535110efb8",
.hash = "122054439ec36ac10987c87ae69f3b041b40b2e451af3fe3ef1fc578b3bad756a800",
},
.zbench = .{
.url = "git+https://github.com/hendriknielaender/zBench#fb3ecae5d035091fd2392a2ec21970c06fc375fa",
.hash = "122095b73930ff5d627429295c669905d85bb9b54394ddc185ad2d61295cc65819e5",
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
"input",
"tests",
"benchmarks",
},
}
10 changes: 10 additions & 0 deletions 2024/24/crossed_wires/input/example_input_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
x00: 1
x01: 1
x02: 1
y00: 0
y01: 1
y02: 0

x00 AND y00 -> z00
x01 XOR y01 -> z01
x02 OR y02 -> z02
47 changes: 47 additions & 0 deletions 2024/24/crossed_wires/input/example_input_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
x00: 1
x01: 0
x02: 1
x03: 1
x04: 0
y00: 1
y01: 1
y02: 1
y03: 1
y04: 1

ntg XOR fgs -> mjb
y02 OR x01 -> tnw
kwq OR kpj -> z05
x00 OR x03 -> fst
tgd XOR rvg -> z01
vdt OR tnw -> bfw
bfw AND frj -> z10
ffh OR nrd -> bqk
y00 AND y03 -> djm
y03 OR y00 -> psh
bqk OR frj -> z08
tnw OR fst -> frj
gnj AND tgd -> z11
bfw XOR mjb -> z00
x03 OR x00 -> vdt
gnj AND wpb -> z02
x04 AND y00 -> kjc
djm OR pbm -> qhw
nrd AND vdt -> hwm
kjc AND fst -> rvg
y04 OR y02 -> fgs
y01 AND x02 -> pbm
ntg OR kjc -> kwq
psh XOR fgs -> tgd
qhw XOR tgd -> z09
pbm OR djm -> kpj
x03 XOR y03 -> ffh
x00 XOR y04 -> ntg
bfw OR bqk -> z06
nrd XOR fgs -> wpb
frj XOR qhw -> z04
bqk OR frj -> z07
y03 OR x01 -> nrd
hwm AND bqk -> z03
tgd XOR rvg -> z12
tnw OR pbm -> gnj
Loading

0 comments on commit 99bd63f

Please sign in to comment.