Skip to content

Commit

Permalink
[2024] Add Day 07: Bridge Repair
Browse files Browse the repository at this point in the history
  • Loading branch information
ACSimon33 committed Dec 14, 2024
1 parent 11025ad commit 91d1947
Show file tree
Hide file tree
Showing 10 changed files with 1,256 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 2024/07/bridge_repair/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 bridge_repair = @import("bridge_repair");

const puzzle_input = @embedFile("puzzle_input");

// Benchmark of part 1
fn task_1(_: std.mem.Allocator) void {
_ = bridge_repair.total_calibration_result(puzzle_input) catch {};
}

// Benchmark of part 2
fn task_2(_: std.mem.Allocator) void {
_ = bridge_repair.total_calibration_result_with_concatenation(puzzle_input) 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 07 - Task 1", task_1, .{});
try bench.add("Day 07 - Task 2", task_2, .{});

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

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

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

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

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

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

const run_step = b.step("run", "Run Bridge Repair (day 07) app");
run_step.dependOn(&run_cmd.step);

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

bridge_repair_tests.root_module.addImport("bridge_repair", bridge_repair);
bridge_repair_tests.root_module.addAnonymousImport("example_input", .{
.root_source_file = b.path("input/example_input.txt"),
});
b.installArtifact(bridge_repair_tests);

const test_step = b.step("test", "Run Bridge Repair (day 07) tests");
test_step.dependOn(&b.addRunArtifact(bridge_repair_tests).step);

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

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

const benchmark_step = b.step("benchmark", "Run Bridge Repair (day 07) benchmarks");
benchmark_step.dependOn(&b.addRunArtifact(bridge_repair_benchmarks).step);
}
23 changes: 23 additions & 0 deletions 2024/07/bridge_repair/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.{
.name = "bridge_repair",
.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",
},
}
9 changes: 9 additions & 0 deletions 2024/07/bridge_repair/input/example_input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
190: 10 19
3267: 81 40 27
83: 17 5
156: 15 6
7290: 6 8 6 15
161011: 16 10 13
192: 17 8 14
21037: 9 7 18 13
292: 11 6 16 20
Loading

0 comments on commit 91d1947

Please sign in to comment.