Skip to content

Commit

Permalink
[2024] Add Day 15: Warehouse Woes
Browse files Browse the repository at this point in the history
  • Loading branch information
ACSimon33 committed Dec 15, 2024
1 parent 91d1947 commit b079d88
Show file tree
Hide file tree
Showing 12 changed files with 704 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 2024/15/warehouse_woes/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 warehouse_woes = @import("warehouse_woes");

const puzzle_input = @embedFile("puzzle_input");

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

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

try stdout.writeAll("\n");
try bench.run(stdout);
}
78 changes: 78 additions & 0 deletions 2024/15/warehouse_woes/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 warehouse_woes = b.addModule("warehouse_woes", .{
.root_source_file = b.path("src/warehouse_woes.zig"),
});

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

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

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

const run_step = b.step("run", "Run Warehouse Woes (day 15) app");
run_step.dependOn(&run_cmd.step);

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

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

const test_step = b.step("test", "Run Warehouse Woes (day 15) tests");
test_step.dependOn(&b.addRunArtifact(warehouse_woes_tests).step);

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

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

const benchmark_step = b.step("benchmark", "Run Warehouse Woes (day 15) benchmarks");
benchmark_step.dependOn(&b.addRunArtifact(warehouse_woes_benchmarks).step);
}
23 changes: 23 additions & 0 deletions 2024/15/warehouse_woes/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.{
.name = "warehouse_woes",
.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/15/warehouse_woes/input/example_input_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
########
#..O.O.#
##@.O..#
#...O..#
#.#.O..#
#...O..#
#......#
########

<^^>>>vv<v>>v<<
21 changes: 21 additions & 0 deletions 2024/15/warehouse_woes/input/example_input_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
##########
#..O..O.O#
#......O.#
#.OO..O.O#
#[email protected].#
#O#..O...#
#O..O..O.#
#.OO.O.OO#
#....O...#
##########

<vv>^<v^>v>^vv^v>v<>v^v<v<^vv<<<^><<><>>v<vvv<>^v^>^<<<><<v<<<v^vv^v>^
vvv<<^>^v^^><<>>><>^<<><^vv^^<>vvv<>><^^v>^>vv<>v<<<<v<^v>^<^^>>>^<v<v
><>vv>v^v^<>><>>>><^^>vv>v<^^^>>v^v^<^^>v^^>v^<^v>v<>>v^v^<v>v^^<^^vv<
<<v<^>>^^^^>>>v^<>vvv^><v<<<>^^^vv^<vvv>^>v<^^^^v<>^>vvvv><>>v^<<^^^^^
^><^><>>><>^^<<^^v>>><^<v>^<vv>>v>>>^v><>^v><<<<v>>v<v<v>vvv>^<><<>^><
^>><>^v<><^vvv<^^<><v<<<<<><^v<<<><<<^^<v<^^^><^>>^<v^><<<^>>^v<v^v<v^
>^>>^v>vv>^<<^v<>><<><<v<<v><>v<^vv<<<>^^v^>^^>>><<^v>>v^v><^^>>^<>vv^
<><^^>^^^<><vvvvv^v<v<<>^v<v>v<<^><<><<><<<^^<<<^<<>><<><^^^>^^<>^>v<>
^^>vv<^v^v<vv>^<><v<^v>^^^>>>^^vvv^>vvv<>>>^<^>>>>>^<<^v>^vvv<>^<><<v>
v^^>>><<^^<>>^v^<v^vv<>v^<<>^<^v^v><^<<<><<^<v><v<>vv>>v><v^<vv<>v^<<^
9 changes: 9 additions & 0 deletions 2024/15/warehouse_woes/input/example_input_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#######
#...#.#
#.....#
#..OO@#
#..O..#
#.....#
#######

<vv<<^^<<^^
Loading

0 comments on commit b079d88

Please sign in to comment.