-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2024] Add Day 17: Chronospatial Computer
- Loading branch information
Showing
11 changed files
with
499 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
2024/17/chronospatial_computer/benchmarks/puzzle_benchmarks.zig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const std = @import("std"); | ||
const zbench = @import("zbench"); | ||
const chronospatial_computer = @import("chronospatial_computer"); | ||
|
||
const puzzle_input = @embedFile("puzzle_input"); | ||
|
||
// Benchmark of part 1 | ||
fn task_1(allocator: std.mem.Allocator) void { | ||
_ = chronospatial_computer.simulate_program(puzzle_input, allocator) catch {}; | ||
} | ||
|
||
// Benchmark of part 2 | ||
fn task_2(allocator: std.mem.Allocator) void { | ||
_ = chronospatial_computer.debug_program(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 17 - Task 1", task_1, .{}); | ||
try bench.add("Day 17 - Task 2", task_2, .{}); | ||
|
||
try stdout.writeAll("\n"); | ||
try bench.run(stdout); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 chronospatial_computer = b.addModule("chronospatial_computer", .{ | ||
.root_source_file = b.path("src/chronospatial_computer.zig"), | ||
}); | ||
|
||
// -------------------------- Main executable --------------------------- \\ | ||
const chronospatial_computer_exe = b.addExecutable(.{ | ||
.name = "chronospatial_computer", | ||
.root_source_file = b.path("src/main.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
const yazap = b.dependency("yazap", .{}); | ||
chronospatial_computer_exe.root_module.addImport("yazap", yazap.module("yazap")); | ||
chronospatial_computer_exe.root_module.addImport("chronospatial_computer", chronospatial_computer); | ||
b.installArtifact(chronospatial_computer_exe); | ||
|
||
const run_cmd = b.addRunArtifact(chronospatial_computer_exe); | ||
run_cmd.step.dependOn(b.getInstallStep()); | ||
if (b.args) |args| { | ||
run_cmd.addArgs(args); | ||
} | ||
|
||
const run_step = b.step("run", "Run Chronospatial Computer (day 17) app"); | ||
run_step.dependOn(&run_cmd.step); | ||
|
||
// --------------------------- Example tests ---------------------------- \\ | ||
const chronospatial_computer_tests = b.addTest(.{ | ||
.name = "chronospatial_computer_tests", | ||
.root_source_file = b.path("tests/example_tests.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
chronospatial_computer_tests.root_module.addImport("chronospatial_computer", chronospatial_computer); | ||
inline for (1..3) |i| { | ||
const num_str = std.fmt.comptimePrint("{!}", .{i}); | ||
chronospatial_computer_tests.root_module.addAnonymousImport( | ||
"example_input_" ++ num_str, | ||
.{ | ||
.root_source_file = b.path("input/example_input_" ++ num_str ++ ".txt"), | ||
}, | ||
); | ||
} | ||
b.installArtifact(chronospatial_computer_tests); | ||
|
||
const test_step = b.step("test", "Run Chronospatial Computer (day 17) tests"); | ||
test_step.dependOn(&b.addRunArtifact(chronospatial_computer_tests).step); | ||
|
||
// ------------------------- Puzzle benchmarks -------------------------- \\ | ||
const chronospatial_computer_benchmarks = b.addExecutable(.{ | ||
.name = "chronospatial_computer_benchmarks", | ||
.root_source_file = b.path("benchmarks/puzzle_benchmarks.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
const zbench = b.dependency("zbench", .{ | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
chronospatial_computer_benchmarks.root_module.addImport("zbench", zbench.module("zbench")); | ||
chronospatial_computer_benchmarks.root_module.addImport("chronospatial_computer", chronospatial_computer); | ||
chronospatial_computer_benchmarks.root_module.addAnonymousImport("puzzle_input", .{ | ||
.root_source_file = b.path("input/puzzle_input.txt"), | ||
}); | ||
b.installArtifact(chronospatial_computer_benchmarks); | ||
|
||
const benchmark_step = b.step("benchmark", "Run Chronospatial Computer (day 17) benchmarks"); | ||
benchmark_step.dependOn(&b.addRunArtifact(chronospatial_computer_benchmarks).step); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.{ | ||
.name = "chronospatial_computer", | ||
.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", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Register A: 729 | ||
Register B: 0 | ||
Register C: 0 | ||
|
||
Program: 0,1,5,4,3,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Register A: 117440 | ||
Register B: 0 | ||
Register C: 0 | ||
|
||
Program: 0,3,5,4,3,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Register A: 28066687 | ||
Register B: 0 | ||
Register C: 0 | ||
|
||
Program: 2,4,1,1,7,5,4,6,0,3,1,4,5,5,3,0 |
Oops, something went wrong.