Skip to content

Commit a385e75

Browse files
committed
[2024] Added Day 25: Code Chronicle
1 parent 8064192 commit a385e75

File tree

8 files changed

+4298
-0
lines changed

8 files changed

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

2024/25/code_chronicle/build.zig

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 code_chronicle = b.addModule("code_chronicle", .{
9+
.root_source_file = b.path("src/code_chronicle.zig"),
10+
});
11+
12+
// -------------------------- Main executable --------------------------- \\
13+
const code_chronicle_exe = b.addExecutable(.{
14+
.name = "code_chronicle",
15+
.root_source_file = b.path("src/main.zig"),
16+
.target = target,
17+
.optimize = optimize,
18+
});
19+
20+
const yazap = b.dependency("yazap", .{});
21+
code_chronicle_exe.root_module.addImport("yazap", yazap.module("yazap"));
22+
code_chronicle_exe.root_module.addImport("code_chronicle", code_chronicle);
23+
b.installArtifact(code_chronicle_exe);
24+
25+
const run_cmd = b.addRunArtifact(code_chronicle_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 Code Chronicle (day 25) app");
32+
run_step.dependOn(&run_cmd.step);
33+
34+
// --------------------------- Example tests ---------------------------- \\
35+
const code_chronicle_tests = b.addTest(.{
36+
.name = "code_chronicle_tests",
37+
.root_source_file = b.path("tests/example_tests.zig"),
38+
.target = target,
39+
.optimize = optimize,
40+
});
41+
42+
code_chronicle_tests.root_module.addImport("code_chronicle", code_chronicle);
43+
code_chronicle_tests.root_module.addAnonymousImport("example_input", .{
44+
.root_source_file = b.path("input/example_input.txt"),
45+
});
46+
b.installArtifact(code_chronicle_tests);
47+
48+
const test_step = b.step("test", "Run Code Chronicle (day 25) tests");
49+
test_step.dependOn(&b.addRunArtifact(code_chronicle_tests).step);
50+
51+
// ------------------------- Puzzle benchmarks -------------------------- \\
52+
const code_chronicle_benchmarks = b.addExecutable(.{
53+
.name = "code_chronicle_benchmarks",
54+
.root_source_file = b.path("benchmarks/puzzle_benchmarks.zig"),
55+
.target = target,
56+
.optimize = optimize,
57+
});
58+
59+
const zbench = b.dependency("zbench", .{
60+
.target = target,
61+
.optimize = optimize,
62+
});
63+
code_chronicle_benchmarks.root_module.addImport("zbench", zbench.module("zbench"));
64+
code_chronicle_benchmarks.root_module.addImport("code_chronicle", code_chronicle);
65+
code_chronicle_benchmarks.root_module.addAnonymousImport("puzzle_input", .{
66+
.root_source_file = b.path("input/puzzle_input.txt"),
67+
});
68+
b.installArtifact(code_chronicle_benchmarks);
69+
70+
const benchmark_step = b.step("benchmark", "Run Code Chronicle (day 25) benchmarks");
71+
benchmark_step.dependOn(&b.addRunArtifact(code_chronicle_benchmarks).step);
72+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.{
2+
.name = "code_chronicle",
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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#####
2+
.####
3+
.####
4+
.####
5+
.#.#.
6+
.#...
7+
.....
8+
9+
#####
10+
##.##
11+
.#.##
12+
...##
13+
...#.
14+
...#.
15+
.....
16+
17+
.....
18+
#....
19+
#....
20+
#...#
21+
#.#.#
22+
#.###
23+
#####
24+
25+
.....
26+
.....
27+
#.#..
28+
###..
29+
###.#
30+
###.#
31+
#####
32+
33+
.....
34+
.....
35+
.....
36+
#....
37+
#.#..
38+
#.#.#
39+
#####

0 commit comments

Comments
 (0)