Skip to content

Commit 99bd63f

Browse files
committed
[2024] Added Day 24: Crossed Wires
1 parent a385e75 commit 99bd63f

File tree

12 files changed

+1623
-0
lines changed

12 files changed

+1623
-0
lines changed

2024/24/crossed_wires/adder.dot

Lines changed: 758 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const std = @import("std");
2+
const zbench = @import("zbench");
3+
const crossed_wires = @import("crossed_wires");
4+
5+
const puzzle_input = @embedFile("puzzle_input");
6+
7+
// Benchmark of part 1
8+
fn task_1(allocator: std.mem.Allocator) void {
9+
_ = crossed_wires.simulate_gates(puzzle_input, allocator) catch {};
10+
}
11+
12+
// Benchmark of part 2
13+
fn task_2(allocator: std.mem.Allocator) void {
14+
_ = crossed_wires.find_wrong_gates(puzzle_input, allocator) catch {};
15+
}
16+
17+
pub fn main() !void {
18+
const stdout = std.io.getStdOut().writer();
19+
var bench = zbench.Benchmark.init(std.heap.page_allocator, .{});
20+
defer bench.deinit();
21+
22+
try bench.add("Day 24 - Task 1", task_1, .{});
23+
try bench.add("Day 24 - Task 2", task_2, .{});
24+
25+
try stdout.writeAll("\n");
26+
try bench.run(stdout);
27+
}

2024/24/crossed_wires/build.zig

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const optimize = b.standardOptimizeOption(.{});
6+
7+
// -------------------------- Solution module --------------------------- \\
8+
const crossed_wires = b.addModule("crossed_wires", .{
9+
.root_source_file = b.path("src/crossed_wires.zig"),
10+
});
11+
12+
// -------------------------- Main executable --------------------------- \\
13+
const crossed_wires_exe = b.addExecutable(.{
14+
.name = "crossed_wires",
15+
.root_source_file = b.path("src/main.zig"),
16+
.target = target,
17+
.optimize = optimize,
18+
});
19+
20+
const yazap = b.dependency("yazap", .{});
21+
crossed_wires_exe.root_module.addImport("yazap", yazap.module("yazap"));
22+
crossed_wires_exe.root_module.addImport("crossed_wires", crossed_wires);
23+
b.installArtifact(crossed_wires_exe);
24+
25+
const run_cmd = b.addRunArtifact(crossed_wires_exe);
26+
run_cmd.step.dependOn(b.getInstallStep());
27+
if (b.args) |args| {
28+
run_cmd.addArgs(args);
29+
}
30+
31+
const run_step = b.step("run", "Run Crossed Wires (day 24) app");
32+
run_step.dependOn(&run_cmd.step);
33+
34+
// --------------------------- Example tests ---------------------------- \\
35+
const crossed_wires_tests = b.addTest(.{
36+
.name = "crossed_wires_tests",
37+
.root_source_file = b.path("tests/example_tests.zig"),
38+
.target = target,
39+
.optimize = optimize,
40+
});
41+
42+
crossed_wires_tests.root_module.addImport("crossed_wires", crossed_wires);
43+
inline for (1..3) |i| {
44+
const num_str = std.fmt.comptimePrint("{!}", .{i});
45+
crossed_wires_tests.root_module.addAnonymousImport(
46+
"example_input_" ++ num_str,
47+
.{
48+
.root_source_file = b.path("input/example_input_" ++ num_str ++ ".txt"),
49+
},
50+
);
51+
}
52+
b.installArtifact(crossed_wires_tests);
53+
54+
const test_step = b.step("test", "Run Crossed Wires (day 24) tests");
55+
test_step.dependOn(&b.addRunArtifact(crossed_wires_tests).step);
56+
57+
// ------------------------- Puzzle benchmarks -------------------------- \\
58+
const crossed_wires_benchmarks = b.addExecutable(.{
59+
.name = "crossed_wires_benchmarks",
60+
.root_source_file = b.path("benchmarks/puzzle_benchmarks.zig"),
61+
.target = target,
62+
.optimize = optimize,
63+
});
64+
65+
const zbench = b.dependency("zbench", .{
66+
.target = target,
67+
.optimize = optimize,
68+
});
69+
crossed_wires_benchmarks.root_module.addImport("zbench", zbench.module("zbench"));
70+
crossed_wires_benchmarks.root_module.addImport("crossed_wires", crossed_wires);
71+
crossed_wires_benchmarks.root_module.addAnonymousImport("puzzle_input", .{
72+
.root_source_file = b.path("input/puzzle_input.txt"),
73+
});
74+
b.installArtifact(crossed_wires_benchmarks);
75+
76+
const benchmark_step = b.step("benchmark", "Run Crossed Wires (day 24) benchmarks");
77+
benchmark_step.dependOn(&b.addRunArtifact(crossed_wires_benchmarks).step);
78+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.{
2+
.name = "crossed_wires",
3+
.version = "0.1.0",
4+
.minimum_zig_version = "0.13.0",
5+
.dependencies = .{
6+
.yazap = .{
7+
.url = "git+https://github.com/prajwalch/yazap#c2e3122d5dd6192513ba590f229dbc535110efb8",
8+
.hash = "122054439ec36ac10987c87ae69f3b041b40b2e451af3fe3ef1fc578b3bad756a800",
9+
},
10+
.zbench = .{
11+
.url = "git+https://github.com/hendriknielaender/zBench#fb3ecae5d035091fd2392a2ec21970c06fc375fa",
12+
.hash = "122095b73930ff5d627429295c669905d85bb9b54394ddc185ad2d61295cc65819e5",
13+
},
14+
},
15+
.paths = .{
16+
"build.zig",
17+
"build.zig.zon",
18+
"src",
19+
"input",
20+
"tests",
21+
"benchmarks",
22+
},
23+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
x00: 1
2+
x01: 1
3+
x02: 1
4+
y00: 0
5+
y01: 1
6+
y02: 0
7+
8+
x00 AND y00 -> z00
9+
x01 XOR y01 -> z01
10+
x02 OR y02 -> z02
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
x00: 1
2+
x01: 0
3+
x02: 1
4+
x03: 1
5+
x04: 0
6+
y00: 1
7+
y01: 1
8+
y02: 1
9+
y03: 1
10+
y04: 1
11+
12+
ntg XOR fgs -> mjb
13+
y02 OR x01 -> tnw
14+
kwq OR kpj -> z05
15+
x00 OR x03 -> fst
16+
tgd XOR rvg -> z01
17+
vdt OR tnw -> bfw
18+
bfw AND frj -> z10
19+
ffh OR nrd -> bqk
20+
y00 AND y03 -> djm
21+
y03 OR y00 -> psh
22+
bqk OR frj -> z08
23+
tnw OR fst -> frj
24+
gnj AND tgd -> z11
25+
bfw XOR mjb -> z00
26+
x03 OR x00 -> vdt
27+
gnj AND wpb -> z02
28+
x04 AND y00 -> kjc
29+
djm OR pbm -> qhw
30+
nrd AND vdt -> hwm
31+
kjc AND fst -> rvg
32+
y04 OR y02 -> fgs
33+
y01 AND x02 -> pbm
34+
ntg OR kjc -> kwq
35+
psh XOR fgs -> tgd
36+
qhw XOR tgd -> z09
37+
pbm OR djm -> kpj
38+
x03 XOR y03 -> ffh
39+
x00 XOR y04 -> ntg
40+
bfw OR bqk -> z06
41+
nrd XOR fgs -> wpb
42+
frj XOR qhw -> z04
43+
bqk OR frj -> z07
44+
y03 OR x01 -> nrd
45+
hwm AND bqk -> z03
46+
tgd XOR rvg -> z12
47+
tnw OR pbm -> gnj

0 commit comments

Comments
 (0)