diff --git a/2024/00/zig_template/benchmarks/puzzle_benchmarks.zig b/2024/00/zig_template/benchmarks/puzzle_benchmarks.zig index 8087e973..44b998f4 100644 --- a/2024/00/zig_template/benchmarks/puzzle_benchmarks.zig +++ b/2024/00/zig_template/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ const zig_template = @import("zig_template"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = zig_template.solution_1(puzzle_input) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = zig_template.solution_1(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = zig_template.solution_2(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = zig_template.solution_2(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/00/zig_template/src/main.zig b/2024/00/zig_template/src/main.zig index 08b3f45a..4162f7cd 100644 --- a/2024/00/zig_template/src/main.zig +++ b/2024/00/zig_template/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const result_1 = zig_template.solution_1(file_content); + const result_1 = zig_template.solution_1( + file_content, + allocator, + ); try stdout.print("1. Solution: {!}\n", .{result_1}); try bw.flush(); - const result_2 = zig_template.solution_2(file_content); + const result_2 = zig_template.solution_2( + file_content, + allocator, + ); try stdout.print("2. Solution: {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/00/zig_template/src/zig_template.zig b/2024/00/zig_template/src/zig_template.zig index c3f3d91e..07aa9291 100644 --- a/2024/00/zig_template/src/zig_template.zig +++ b/2024/00/zig_template/src/zig_template.zig @@ -1,16 +1,18 @@ const std = @import("std"); const Allocator = std.mem.Allocator; +const ArrayList = std.ArrayList; const string = []const u8; /// Task 1 - /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Solution for task 1. -pub fn solution_1(contents: string) !i32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn solution_1(contents: string, main_allocator: Allocator) !i32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -23,12 +25,16 @@ pub fn solution_1(contents: string) !i32 { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Solution for task 2. -pub fn solution_2(contents: string) !i32 { - const lines = std.mem.split(u8, contents, "\n"); - _ = lines; +pub fn solution_2(contents: string, main_allocator: Allocator) !i32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); + defer arena.deinit(); + + const allocator = arena.allocator(); + _ = try parse(contents, allocator); return 1; } @@ -39,6 +45,7 @@ pub fn solution_2(contents: string) !i32 { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/00/zig_template/tests/example_tests.zig b/2024/00/zig_template/tests/example_tests.zig index 08779b3a..65184c90 100644 --- a/2024/00/zig_template/tests/example_tests.zig +++ b/2024/00/zig_template/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1" { const example_input = @embedFile("example_input"); try testing.expectEqual( 0, - zig_template.solution_1(example_input), + zig_template.solution_1(example_input, std.testing.allocator), ); } @@ -16,6 +16,6 @@ test "task_2" { const example_input = @embedFile("example_input"); try testing.expectEqual( 1, - zig_template.solution_2(example_input), + zig_template.solution_2(example_input, std.testing.allocator), ); } diff --git a/2024/01/historian_hysteria/benchmarks/puzzle_benchmarks.zig b/2024/01/historian_hysteria/benchmarks/puzzle_benchmarks.zig index 12f3c872..ff31cf66 100644 --- a/2024/01/historian_hysteria/benchmarks/puzzle_benchmarks.zig +++ b/2024/01/historian_hysteria/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ const historian_hysteria = @import("historian_hysteria"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = historian_hysteria.list_distance(puzzle_input) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = historian_hysteria.list_distance(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = historian_hysteria.list_similarity(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = historian_hysteria.list_similarity(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/01/historian_hysteria/src/historian_hysteria.zig b/2024/01/historian_hysteria/src/historian_hysteria.zig index 2ee63b7a..f8868594 100644 --- a/2024/01/historian_hysteria/src/historian_hysteria.zig +++ b/2024/01/historian_hysteria/src/historian_hysteria.zig @@ -7,11 +7,12 @@ const string = []const u8; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Distance of the two lists. -pub fn list_distance(contents: string) !u32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn list_distance(contents: string, main_allocator: Allocator) !u32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -32,11 +33,12 @@ pub fn list_distance(contents: string) !u32 { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Similarity of the two lists. -pub fn list_similarity(contents: string) !i32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn list_similarity(contents: string, main_allocator: Allocator) !i32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -57,6 +59,7 @@ pub fn list_similarity(contents: string) !i32 { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/01/historian_hysteria/src/main.zig b/2024/01/historian_hysteria/src/main.zig index 1125af03..93d3604d 100644 --- a/2024/01/historian_hysteria/src/main.zig +++ b/2024/01/historian_hysteria/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const result_1 = historian_hysteria.list_distance(file_content); + const result_1 = historian_hysteria.list_distance( + file_content, + allocator, + ); try stdout.print("List distance: {!}\n", .{result_1}); try bw.flush(); - const result_2 = historian_hysteria.list_similarity(file_content); + const result_2 = historian_hysteria.list_similarity( + file_content, + allocator, + ); try stdout.print("List similarity: {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/01/historian_hysteria/tests/example_tests.zig b/2024/01/historian_hysteria/tests/example_tests.zig index c0d60ed0..748869a5 100644 --- a/2024/01/historian_hysteria/tests/example_tests.zig +++ b/2024/01/historian_hysteria/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1" { const example_input = @embedFile("example_input"); try testing.expectEqual( 11, - historian_hysteria.list_distance(example_input), + historian_hysteria.list_distance(example_input, std.testing.allocator), ); } @@ -16,6 +16,6 @@ test "task_2" { const example_input = @embedFile("example_input"); try testing.expectEqual( 31, - historian_hysteria.list_similarity(example_input), + historian_hysteria.list_similarity(example_input, std.testing.allocator), ); } diff --git a/2024/02/red_nosed_reports/benchmarks/puzzle_benchmarks.zig b/2024/02/red_nosed_reports/benchmarks/puzzle_benchmarks.zig index 31413c76..c8a1ebcd 100644 --- a/2024/02/red_nosed_reports/benchmarks/puzzle_benchmarks.zig +++ b/2024/02/red_nosed_reports/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ const red_nosed_reports = @import("red_nosed_reports"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = red_nosed_reports.number_of_safe_reports(puzzle_input) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = red_nosed_reports.number_of_safe_reports(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = red_nosed_reports.number_of_partially_safe_reports(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = red_nosed_reports.number_of_partially_safe_reports(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/02/red_nosed_reports/src/main.zig b/2024/02/red_nosed_reports/src/main.zig index 0a44b731..b82c169d 100644 --- a/2024/02/red_nosed_reports/src/main.zig +++ b/2024/02/red_nosed_reports/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const safe_reports = red_nosed_reports.number_of_safe_reports(file_content); + const safe_reports = red_nosed_reports.number_of_safe_reports( + file_content, + allocator, + ); try stdout.print("Number of safe reports: {!}\n", .{safe_reports}); try bw.flush(); - const partially_safe_reports = red_nosed_reports.number_of_partially_safe_reports(file_content); + const partially_safe_reports = red_nosed_reports.number_of_partially_safe_reports( + file_content, + allocator, + ); try stdout.print("Number of partially safe reports: {!}\n", .{partially_safe_reports}); try bw.flush(); } diff --git a/2024/02/red_nosed_reports/src/red_nosed_reports.zig b/2024/02/red_nosed_reports/src/red_nosed_reports.zig index c65ce4d3..e8bbe784 100644 --- a/2024/02/red_nosed_reports/src/red_nosed_reports.zig +++ b/2024/02/red_nosed_reports/src/red_nosed_reports.zig @@ -7,11 +7,12 @@ const string = []const u8; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Number of fully safe reports. -pub fn number_of_safe_reports(contents: string) !i32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn number_of_safe_reports(contents: string, main_allocator: Allocator) !i32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -32,11 +33,12 @@ pub fn number_of_safe_reports(contents: string) !i32 { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Number of fully safe reports. -pub fn number_of_partially_safe_reports(contents: string) !i32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn number_of_partially_safe_reports(contents: string, main_allocator: Allocator) !i32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -67,6 +69,7 @@ const Report = struct { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/02/red_nosed_reports/tests/example_tests.zig b/2024/02/red_nosed_reports/tests/example_tests.zig index 5f0ec4a2..c44449e0 100644 --- a/2024/02/red_nosed_reports/tests/example_tests.zig +++ b/2024/02/red_nosed_reports/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1" { const example_input = @embedFile("example_input"); try testing.expectEqual( 2, - red_nosed_reports.number_of_safe_reports(example_input), + red_nosed_reports.number_of_safe_reports(example_input, std.testing.allocator), ); } @@ -16,6 +16,6 @@ test "task_2" { const example_input = @embedFile("example_input"); try testing.expectEqual( 4, - red_nosed_reports.number_of_partially_safe_reports(example_input), + red_nosed_reports.number_of_partially_safe_reports(example_input, std.testing.allocator), ); } diff --git a/2024/03/mull_it_over/benchmarks/puzzle_benchmarks.zig b/2024/03/mull_it_over/benchmarks/puzzle_benchmarks.zig index 4e6a6981..1f64cad0 100644 --- a/2024/03/mull_it_over/benchmarks/puzzle_benchmarks.zig +++ b/2024/03/mull_it_over/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ const mull_it_over = @import("mull_it_over"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = mull_it_over.sum_of_multiplication_instructions(puzzle_input) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = mull_it_over.sum_of_multiplication_instructions(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = mull_it_over.conditional_sum_of_multiplication_instructions(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = mull_it_over.conditional_sum_of_multiplication_instructions(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/03/mull_it_over/src/main.zig b/2024/03/mull_it_over/src/main.zig index 6e3a424d..6a9fb9d9 100644 --- a/2024/03/mull_it_over/src/main.zig +++ b/2024/03/mull_it_over/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const result_1 = mull_it_over.sum_of_multiplication_instructions(file_content); + const result_1 = mull_it_over.sum_of_multiplication_instructions( + file_content, + allocator, + ); try stdout.print("Sum of all multiplication instructions: {!}\n", .{result_1}); try bw.flush(); - const result_2 = mull_it_over.conditional_sum_of_multiplication_instructions(file_content); + const result_2 = mull_it_over.conditional_sum_of_multiplication_instructions( + file_content, + allocator, + ); try stdout.print("Conditional sum of multiplication instructions: {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/03/mull_it_over/src/mull_it_over.zig b/2024/03/mull_it_over/src/mull_it_over.zig index 36f68eb0..ab081de5 100644 --- a/2024/03/mull_it_over/src/mull_it_over.zig +++ b/2024/03/mull_it_over/src/mull_it_over.zig @@ -6,10 +6,11 @@ const string = []const u8; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Sum of all multiplications. -pub fn sum_of_multiplication_instructions(contents: string) !u32 { +pub fn sum_of_multiplication_instructions(contents: string, _: Allocator) !u32 { const min_instruction_len: usize = 8; var product_sum: u32 = 0; @@ -28,10 +29,11 @@ pub fn sum_of_multiplication_instructions(contents: string) !u32 { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Sum of all active multiplications. -pub fn conditional_sum_of_multiplication_instructions(contents: string) !u32 { +pub fn conditional_sum_of_multiplication_instructions(contents: string, _: Allocator) !u32 { const min_instruction_len: usize = 8; var product_sum: u32 = 0; diff --git a/2024/03/mull_it_over/tests/example_tests.zig b/2024/03/mull_it_over/tests/example_tests.zig index 7f97af22..0be2500a 100644 --- a/2024/03/mull_it_over/tests/example_tests.zig +++ b/2024/03/mull_it_over/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1_input_1" { const example_input = @embedFile("example_input_1"); try testing.expectEqual( 161, - mull_it_over.sum_of_multiplication_instructions(example_input), + mull_it_over.sum_of_multiplication_instructions(example_input, std.testing.allocator), ); } @@ -16,7 +16,7 @@ test "task_2_input_1" { const example_input = @embedFile("example_input_1"); try testing.expectEqual( 161, - mull_it_over.conditional_sum_of_multiplication_instructions(example_input), + mull_it_over.conditional_sum_of_multiplication_instructions(example_input, std.testing.allocator), ); } @@ -24,6 +24,6 @@ test "task_2_input_2" { const example_input = @embedFile("example_input_2"); try testing.expectEqual( 48, - mull_it_over.conditional_sum_of_multiplication_instructions(example_input), + mull_it_over.conditional_sum_of_multiplication_instructions(example_input, std.testing.allocator), ); } diff --git a/2024/04/ceres_search/benchmarks/puzzle_benchmarks.zig b/2024/04/ceres_search/benchmarks/puzzle_benchmarks.zig index 8396b6d3..c90d16bc 100644 --- a/2024/04/ceres_search/benchmarks/puzzle_benchmarks.zig +++ b/2024/04/ceres_search/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ const ceres_search = @import("ceres_search"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = ceres_search.xmas_count(puzzle_input) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = ceres_search.xmas_count(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = ceres_search.x_mas_count(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = ceres_search.x_mas_count(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/04/ceres_search/src/ceres_search.zig b/2024/04/ceres_search/src/ceres_search.zig index 0f76ad0a..8c085093 100644 --- a/2024/04/ceres_search/src/ceres_search.zig +++ b/2024/04/ceres_search/src/ceres_search.zig @@ -7,11 +7,12 @@ const string = []const u8; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Amount of XMAS strings. -pub fn xmas_count(contents: string) !u32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn xmas_count(contents: string, main_allocator: Allocator) !u32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -29,11 +30,12 @@ pub fn xmas_count(contents: string) !u32 { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Amount of X-MAS patterns. -pub fn x_mas_count(contents: string) !u32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn x_mas_count(contents: string, main_allocator: Allocator) !u32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -174,6 +176,7 @@ const WordSearch = struct { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/04/ceres_search/src/main.zig b/2024/04/ceres_search/src/main.zig index fd7b5827..647d1681 100644 --- a/2024/04/ceres_search/src/main.zig +++ b/2024/04/ceres_search/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const result_1 = ceres_search.xmas_count(file_content); + const result_1 = ceres_search.xmas_count( + file_content, + allocator, + ); try stdout.print("Amount of XMAS strings: {!}\n", .{result_1}); try bw.flush(); - const result_2 = ceres_search.x_mas_count(file_content); + const result_2 = ceres_search.x_mas_count( + file_content, + allocator, + ); try stdout.print("Amount of X-MAS patterns: {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/04/ceres_search/tests/example_tests.zig b/2024/04/ceres_search/tests/example_tests.zig index 82ec946f..43053397 100644 --- a/2024/04/ceres_search/tests/example_tests.zig +++ b/2024/04/ceres_search/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1" { const example_input = @embedFile("example_input"); try testing.expectEqual( 18, - ceres_search.xmas_count(example_input), + ceres_search.xmas_count(example_input, std.testing.allocator), ); } @@ -16,6 +16,6 @@ test "task_2" { const example_input = @embedFile("example_input"); try testing.expectEqual( 9, - ceres_search.x_mas_count(example_input), + ceres_search.x_mas_count(example_input, std.testing.allocator), ); } diff --git a/2024/05/print_queue/benchmarks/puzzle_benchmarks.zig b/2024/05/print_queue/benchmarks/puzzle_benchmarks.zig index f8e4c459..fc07fd5c 100644 --- a/2024/05/print_queue/benchmarks/puzzle_benchmarks.zig +++ b/2024/05/print_queue/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ const print_queue = @import("print_queue"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = print_queue.middle_page_sum_of_valid_updates(puzzle_input) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = print_queue.middle_page_sum_of_valid_updates(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = print_queue.middle_page_sum_of_fixed_updates(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = print_queue.middle_page_sum_of_fixed_updates(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/05/print_queue/src/main.zig b/2024/05/print_queue/src/main.zig index 2ea4d454..4e522fc4 100644 --- a/2024/05/print_queue/src/main.zig +++ b/2024/05/print_queue/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const result_1 = print_queue.middle_page_sum_of_valid_updates(file_content); + const result_1 = print_queue.middle_page_sum_of_valid_updates( + file_content, + allocator, + ); try stdout.print("Middle page number sum of valid updates: {!}\n", .{result_1}); try bw.flush(); - const result_2 = print_queue.middle_page_sum_of_fixed_updates(file_content); + const result_2 = print_queue.middle_page_sum_of_fixed_updates( + file_content, + allocator, + ); try stdout.print("Middle page number sum of fixed updates: {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/05/print_queue/src/print_queue.zig b/2024/05/print_queue/src/print_queue.zig index ba7de926..0759ac12 100644 --- a/2024/05/print_queue/src/print_queue.zig +++ b/2024/05/print_queue/src/print_queue.zig @@ -8,11 +8,12 @@ const string = []const u8; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Sum of the middle page numbers -pub fn middle_page_sum_of_valid_updates(contents: string) !u32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn middle_page_sum_of_valid_updates(contents: string, main_allocator: Allocator) !u32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -39,11 +40,12 @@ pub fn middle_page_sum_of_valid_updates(contents: string) !u32 { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Sum of the middle page numbers -pub fn middle_page_sum_of_fixed_updates(contents: string) !u32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn middle_page_sum_of_fixed_updates(contents: string, main_allocator: Allocator) !u32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -137,6 +139,7 @@ const Update = struct { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/05/print_queue/tests/example_tests.zig b/2024/05/print_queue/tests/example_tests.zig index cc5a6164..1484686c 100644 --- a/2024/05/print_queue/tests/example_tests.zig +++ b/2024/05/print_queue/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1" { const example_input = @embedFile("example_input"); try testing.expectEqual( 143, - print_queue.middle_page_sum_of_valid_updates(example_input), + print_queue.middle_page_sum_of_valid_updates(example_input, std.testing.allocator), ); } @@ -16,6 +16,6 @@ test "task_2" { const example_input = @embedFile("example_input"); try testing.expectEqual( 123, - print_queue.middle_page_sum_of_fixed_updates(example_input), + print_queue.middle_page_sum_of_fixed_updates(example_input, std.testing.allocator), ); } diff --git a/2024/06/guard_gallivant/benchmarks/puzzle_benchmarks.zig b/2024/06/guard_gallivant/benchmarks/puzzle_benchmarks.zig index 7cec817a..7e173c0a 100644 --- a/2024/06/guard_gallivant/benchmarks/puzzle_benchmarks.zig +++ b/2024/06/guard_gallivant/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ const guard_gallivant = @import("guard_gallivant"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = guard_gallivant.visited_positions(puzzle_input) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = guard_gallivant.visited_positions(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = guard_gallivant.closed_loops(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = guard_gallivant.closed_loops(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/06/guard_gallivant/src/guard_gallivant.zig b/2024/06/guard_gallivant/src/guard_gallivant.zig index c8f8c867..e611c0bf 100644 --- a/2024/06/guard_gallivant/src/guard_gallivant.zig +++ b/2024/06/guard_gallivant/src/guard_gallivant.zig @@ -8,11 +8,12 @@ const string = []const u8; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Amount of distinct positions. -pub fn visited_positions(contents: string) !usize { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn visited_positions(contents: string, main_allocator: Allocator) !usize { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -32,11 +33,12 @@ pub fn visited_positions(contents: string) !usize { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Amount of closed loops. -pub fn closed_loops(contents: string) !usize { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn closed_loops(contents: string, main_allocator: Allocator) !usize { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -170,6 +172,7 @@ fn is_guard_inside(map: ObstacleMap, guard: Guard) bool { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/06/guard_gallivant/src/main.zig b/2024/06/guard_gallivant/src/main.zig index d7dc0d98..a53d275d 100644 --- a/2024/06/guard_gallivant/src/main.zig +++ b/2024/06/guard_gallivant/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const result_1 = guard_gallivant.visited_positions(file_content); + const result_1 = guard_gallivant.visited_positions( + file_content, + allocator, + ); try stdout.print("Amount of visited positions: {!}\n", .{result_1}); try bw.flush(); - const result_2 = guard_gallivant.closed_loops(file_content); + const result_2 = guard_gallivant.closed_loops( + file_content, + allocator, + ); try stdout.print("Amount of possible loops: {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/06/guard_gallivant/tests/example_tests.zig b/2024/06/guard_gallivant/tests/example_tests.zig index db9a11e1..1df6b8f6 100644 --- a/2024/06/guard_gallivant/tests/example_tests.zig +++ b/2024/06/guard_gallivant/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1" { const example_input = @embedFile("example_input"); try testing.expectEqual( 41, - guard_gallivant.visited_positions(example_input), + guard_gallivant.visited_positions(example_input, std.testing.allocator), ); } @@ -16,6 +16,6 @@ test "task_2" { const example_input = @embedFile("example_input"); try testing.expectEqual( 6, - guard_gallivant.closed_loops(example_input), + guard_gallivant.closed_loops(example_input, std.testing.allocator), ); } diff --git a/2024/07/bridge_repair/benchmarks/puzzle_benchmarks.zig b/2024/07/bridge_repair/benchmarks/puzzle_benchmarks.zig index de05d7bb..4afdf3ef 100644 --- a/2024/07/bridge_repair/benchmarks/puzzle_benchmarks.zig +++ b/2024/07/bridge_repair/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ 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 {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = bridge_repair.total_calibration_result(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = bridge_repair.total_calibration_result_with_concatenation(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = bridge_repair.total_calibration_result_with_concatenation(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/07/bridge_repair/src/bridge_repair.zig b/2024/07/bridge_repair/src/bridge_repair.zig index 0bf6cc04..95ebcadb 100644 --- a/2024/07/bridge_repair/src/bridge_repair.zig +++ b/2024/07/bridge_repair/src/bridge_repair.zig @@ -9,11 +9,12 @@ const OpType = *const fn (a: u64, b: u64) anyerror!u64; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - The total calibration results. -pub fn total_calibration_result(contents: string) !u64 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn total_calibration_result(contents: string, main_allocator: Allocator) !u64 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -39,11 +40,12 @@ pub fn total_calibration_result(contents: string) !u64 { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - The total calibration results. -pub fn total_calibration_result_with_concatenation(contents: string) !u64 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn total_calibration_result_with_concatenation(contents: string, main_allocator: Allocator) !u64 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -166,6 +168,7 @@ fn concat_operator(a: u64, b: u64) !u64 { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/07/bridge_repair/src/main.zig b/2024/07/bridge_repair/src/main.zig index be309e4c..5ecf0f90 100644 --- a/2024/07/bridge_repair/src/main.zig +++ b/2024/07/bridge_repair/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const result_1 = bridge_repair.total_calibration_result(file_content); + const result_1 = bridge_repair.total_calibration_result( + file_content, + allocator, + ); try stdout.print("Total calibration result (+, *): {!}\n", .{result_1}); try bw.flush(); - const result_2 = bridge_repair.total_calibration_result_with_concatenation(file_content); + const result_2 = bridge_repair.total_calibration_result_with_concatenation( + file_content, + allocator, + ); try stdout.print("Total calibration result (+, *, ||): {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/07/bridge_repair/tests/example_tests.zig b/2024/07/bridge_repair/tests/example_tests.zig index 77fbd921..866ce37d 100644 --- a/2024/07/bridge_repair/tests/example_tests.zig +++ b/2024/07/bridge_repair/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1" { const example_input = @embedFile("example_input"); try testing.expectEqual( 3749, - bridge_repair.total_calibration_result(example_input), + bridge_repair.total_calibration_result(example_input, std.testing.allocator), ); } @@ -16,6 +16,6 @@ test "task_2" { const example_input = @embedFile("example_input"); try testing.expectEqual( 11387, - bridge_repair.total_calibration_result_with_concatenation(example_input), + bridge_repair.total_calibration_result_with_concatenation(example_input, std.testing.allocator), ); } diff --git a/2024/09/disk_fragmenter/benchmarks/puzzle_benchmarks.zig b/2024/09/disk_fragmenter/benchmarks/puzzle_benchmarks.zig index 571404b6..acda682b 100644 --- a/2024/09/disk_fragmenter/benchmarks/puzzle_benchmarks.zig +++ b/2024/09/disk_fragmenter/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ const disk_fragmenter = @import("disk_fragmenter"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = disk_fragmenter.checksum_of_fragmented_disk(puzzle_input) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = disk_fragmenter.checksum_of_fragmented_disk(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = disk_fragmenter.checksum_of_defragmented_disk(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = disk_fragmenter.checksum_of_defragmented_disk(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/09/disk_fragmenter/src/disk_fragmenter.zig b/2024/09/disk_fragmenter/src/disk_fragmenter.zig index 92f11316..06decc96 100644 --- a/2024/09/disk_fragmenter/src/disk_fragmenter.zig +++ b/2024/09/disk_fragmenter/src/disk_fragmenter.zig @@ -8,11 +8,12 @@ const string = []const u8; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Checksum of the compressed (fragmented) disk. -pub fn checksum_of_fragmented_disk(contents: string) !usize { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn checksum_of_fragmented_disk(contents: string, main_allocator: Allocator) !usize { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -60,11 +61,12 @@ pub fn checksum_of_fragmented_disk(contents: string) !usize { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Checksum of the compressed (defragmented) disk. -pub fn checksum_of_defragmented_disk(contents: string) !usize { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn checksum_of_defragmented_disk(contents: string, main_allocator: Allocator) !usize { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -141,6 +143,7 @@ fn gauss_sum(num: usize) usize { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/09/disk_fragmenter/src/main.zig b/2024/09/disk_fragmenter/src/main.zig index 362208f1..b802e120 100644 --- a/2024/09/disk_fragmenter/src/main.zig +++ b/2024/09/disk_fragmenter/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const result_1 = disk_fragmenter.checksum_of_fragmented_disk(file_content); + const result_1 = disk_fragmenter.checksum_of_fragmented_disk( + file_content, + allocator, + ); try stdout.print("Checksum of fragmented compressed disk: {!}\n", .{result_1}); try bw.flush(); - const result_2 = disk_fragmenter.checksum_of_defragmented_disk(file_content); + const result_2 = disk_fragmenter.checksum_of_defragmented_disk( + file_content, + allocator, + ); try stdout.print("Checksum of defragmented compressed disk: {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/09/disk_fragmenter/tests/example_tests.zig b/2024/09/disk_fragmenter/tests/example_tests.zig index 44b46049..a9402a82 100644 --- a/2024/09/disk_fragmenter/tests/example_tests.zig +++ b/2024/09/disk_fragmenter/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1" { const example_input = @embedFile("example_input"); try testing.expectEqual( 1928, - disk_fragmenter.checksum_of_fragmented_disk(example_input), + disk_fragmenter.checksum_of_fragmented_disk(example_input, std.testing.allocator), ); } @@ -16,6 +16,6 @@ test "task_2" { const example_input = @embedFile("example_input"); try testing.expectEqual( 2858, - disk_fragmenter.checksum_of_defragmented_disk(example_input), + disk_fragmenter.checksum_of_defragmented_disk(example_input, std.testing.allocator), ); } diff --git a/2024/10/hoof_it/benchmarks/puzzle_benchmarks.zig b/2024/10/hoof_it/benchmarks/puzzle_benchmarks.zig index e4e397e2..955620ed 100644 --- a/2024/10/hoof_it/benchmarks/puzzle_benchmarks.zig +++ b/2024/10/hoof_it/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ const hoof_it = @import("hoof_it"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = hoof_it.sum_of_trailhead_scores(puzzle_input) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = hoof_it.sum_of_trailhead_scores(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = hoof_it.sum_of_trailhead_ratings(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = hoof_it.sum_of_trailhead_ratings(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/10/hoof_it/src/hoof_it.zig b/2024/10/hoof_it/src/hoof_it.zig index 05d994b5..28def155 100644 --- a/2024/10/hoof_it/src/hoof_it.zig +++ b/2024/10/hoof_it/src/hoof_it.zig @@ -11,11 +11,12 @@ const assert = std.debug.assert; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Sum of trailhead scores. -pub fn sum_of_trailhead_scores(contents: string) !usize { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn sum_of_trailhead_scores(contents: string, main_allocator: Allocator) !usize { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -47,11 +48,12 @@ pub fn sum_of_trailhead_scores(contents: string) !usize { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Sum of trailhead ratings. -pub fn sum_of_trailhead_ratings(contents: string) !usize { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn sum_of_trailhead_ratings(contents: string, main_allocator: Allocator) !usize { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -267,6 +269,7 @@ const HikingMap = struct { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/10/hoof_it/src/main.zig b/2024/10/hoof_it/src/main.zig index f502e478..14cc5142 100644 --- a/2024/10/hoof_it/src/main.zig +++ b/2024/10/hoof_it/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const result_1 = hoof_it.sum_of_trailhead_scores(file_content); + const result_1 = hoof_it.sum_of_trailhead_scores( + file_content, + allocator, + ); try stdout.print("Sum of trailhead scores: {!}\n", .{result_1}); try bw.flush(); - const result_2 = hoof_it.sum_of_trailhead_ratings(file_content); + const result_2 = hoof_it.sum_of_trailhead_ratings( + file_content, + allocator, + ); try stdout.print("Sum of trailhead ratings: {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/10/hoof_it/tests/example_tests.zig b/2024/10/hoof_it/tests/example_tests.zig index b5887b4d..99d30859 100644 --- a/2024/10/hoof_it/tests/example_tests.zig +++ b/2024/10/hoof_it/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1_input_1" { const example_input = @embedFile("example_input_1"); try testing.expectEqual( 36, - hoof_it.sum_of_trailhead_scores(example_input), + hoof_it.sum_of_trailhead_scores(example_input, std.testing.allocator), ); } @@ -15,7 +15,7 @@ test "task_1_input_2" { const example_input = @embedFile("example_input_2"); try testing.expectEqual( 2, - hoof_it.sum_of_trailhead_scores(example_input), + hoof_it.sum_of_trailhead_scores(example_input, std.testing.allocator), ); } @@ -23,7 +23,7 @@ test "task_1_input_3" { const example_input = @embedFile("example_input_3"); try testing.expectEqual( 4, - hoof_it.sum_of_trailhead_scores(example_input), + hoof_it.sum_of_trailhead_scores(example_input, std.testing.allocator), ); } @@ -31,7 +31,7 @@ test "task_1_input_4" { const example_input = @embedFile("example_input_4"); try testing.expectEqual( 3, - hoof_it.sum_of_trailhead_scores(example_input), + hoof_it.sum_of_trailhead_scores(example_input, std.testing.allocator), ); } @@ -40,7 +40,7 @@ test "task_2_input_1" { const example_input = @embedFile("example_input_1"); try testing.expectEqual( 81, - hoof_it.sum_of_trailhead_ratings(example_input), + hoof_it.sum_of_trailhead_ratings(example_input, std.testing.allocator), ); } @@ -48,7 +48,7 @@ test "task_2_input_5" { const example_input = @embedFile("example_input_5"); try testing.expectEqual( 3, - hoof_it.sum_of_trailhead_ratings(example_input), + hoof_it.sum_of_trailhead_ratings(example_input, std.testing.allocator), ); } @@ -56,7 +56,7 @@ test "task_2_input_6" { const example_input = @embedFile("example_input_6"); try testing.expectEqual( 13, - hoof_it.sum_of_trailhead_ratings(example_input), + hoof_it.sum_of_trailhead_ratings(example_input, std.testing.allocator), ); } @@ -64,6 +64,6 @@ test "task_2_input_7" { const example_input = @embedFile("example_input_7"); try testing.expectEqual( 227, - hoof_it.sum_of_trailhead_ratings(example_input), + hoof_it.sum_of_trailhead_ratings(example_input, std.testing.allocator), ); } diff --git a/2024/11/plutonian_pebbles/benchmarks/puzzle_benchmarks.zig b/2024/11/plutonian_pebbles/benchmarks/puzzle_benchmarks.zig index 928e979c..bbc524e8 100644 --- a/2024/11/plutonian_pebbles/benchmarks/puzzle_benchmarks.zig +++ b/2024/11/plutonian_pebbles/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ const plutonian_pebbles = @import("plutonian_pebbles"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = plutonian_pebbles.amount_of_stones(puzzle_input, 25) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = plutonian_pebbles.amount_of_stones(puzzle_input, 25, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = plutonian_pebbles.amount_of_stones(puzzle_input, 75) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = plutonian_pebbles.amount_of_stones(puzzle_input, 75, allocator) catch {}; } pub fn main() !void { diff --git a/2024/11/plutonian_pebbles/src/main.zig b/2024/11/plutonian_pebbles/src/main.zig index 9f287b3f..cab4a6ba 100644 --- a/2024/11/plutonian_pebbles/src/main.zig +++ b/2024/11/plutonian_pebbles/src/main.zig @@ -63,7 +63,11 @@ pub fn main() !void { return; } - const result = plutonian_pebbles.amount_of_stones(file_content, blinks); + const result = plutonian_pebbles.amount_of_stones( + file_content, + blinks, + allocator, + ); try stdout.print("Amount of stones: {!}\n", .{result}); try bw.flush(); } diff --git a/2024/11/plutonian_pebbles/src/plutonian_pebbles.zig b/2024/11/plutonian_pebbles/src/plutonian_pebbles.zig index 9ce075c0..d7437f00 100644 --- a/2024/11/plutonian_pebbles/src/plutonian_pebbles.zig +++ b/2024/11/plutonian_pebbles/src/plutonian_pebbles.zig @@ -10,12 +10,13 @@ const string = []const u8; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `blinks`: Amount of blinks. /// /// Returns: /// - The amount of stones after all blinks. -pub fn amount_of_stones(contents: string, blinks: usize) !u64 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn amount_of_stones(contents: string, blinks: usize, main_allocator: Allocator) !u64 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -70,6 +71,7 @@ fn blink(stones: HashMap(u64, u64), new_stones: *HashMap(u64, u64)) !void { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: @@ -90,6 +92,7 @@ fn parse(contents: string, allocator: Allocator) !HashMap(u64, u64) { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/11/plutonian_pebbles/tests/example_tests.zig b/2024/11/plutonian_pebbles/tests/example_tests.zig index d8f518dd..f6b65828 100644 --- a/2024/11/plutonian_pebbles/tests/example_tests.zig +++ b/2024/11/plutonian_pebbles/tests/example_tests.zig @@ -7,6 +7,10 @@ test "task_1" { const example_input = @embedFile("example_input"); try testing.expectEqual( 55312, - plutonian_pebbles.amount_of_stones(example_input, 25), + plutonian_pebbles.amount_of_stones( + example_input, + 25, + std.testing.allocator, + ), ); } diff --git a/2024/12/garden_groups/benchmarks/puzzle_benchmarks.zig b/2024/12/garden_groups/benchmarks/puzzle_benchmarks.zig index 3212df32..9467e577 100644 --- a/2024/12/garden_groups/benchmarks/puzzle_benchmarks.zig +++ b/2024/12/garden_groups/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ const garden_groups = @import("garden_groups"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = garden_groups.fence_cost(puzzle_input) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = garden_groups.fence_cost(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = garden_groups.fence_cost_with_bulk_discount(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = garden_groups.fence_cost_with_bulk_discount(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/12/garden_groups/src/garden_groups.zig b/2024/12/garden_groups/src/garden_groups.zig index 65825e30..d536643f 100644 --- a/2024/12/garden_groups/src/garden_groups.zig +++ b/2024/12/garden_groups/src/garden_groups.zig @@ -7,11 +7,12 @@ const string = []const u8; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - The fence cost. -pub fn fence_cost(contents: string) !u32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn fence_cost(contents: string, main_allocator: Allocator) !u32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -31,11 +32,12 @@ pub fn fence_cost(contents: string) !u32 { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - The fence cost. -pub fn fence_cost_with_bulk_discount(contents: string) !u32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn fence_cost_with_bulk_discount(contents: string, main_allocator: Allocator) !u32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -302,6 +304,7 @@ const Garden = struct { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/12/garden_groups/src/main.zig b/2024/12/garden_groups/src/main.zig index 636c7c6a..dbf52825 100644 --- a/2024/12/garden_groups/src/main.zig +++ b/2024/12/garden_groups/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const result_1 = garden_groups.fence_cost(file_content); + const result_1 = garden_groups.fence_cost( + file_content, + allocator, + ); try stdout.print("Cost of all fences: {!}\n", .{result_1}); try bw.flush(); - const result_2 = garden_groups.fence_cost_with_bulk_discount(file_content); + const result_2 = garden_groups.fence_cost_with_bulk_discount( + file_content, + allocator, + ); try stdout.print("Fence cost with bulk discount: {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/12/garden_groups/tests/example_tests.zig b/2024/12/garden_groups/tests/example_tests.zig index 79fa6284..9ba48bf4 100644 --- a/2024/12/garden_groups/tests/example_tests.zig +++ b/2024/12/garden_groups/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1_input_1" { const example_input = @embedFile("example_input_1"); try testing.expectEqual( 140, - garden_groups.fence_cost(example_input), + garden_groups.fence_cost(example_input, std.testing.allocator), ); } @@ -15,7 +15,7 @@ test "task_1_input_2" { const example_input = @embedFile("example_input_2"); try testing.expectEqual( 772, - garden_groups.fence_cost(example_input), + garden_groups.fence_cost(example_input, std.testing.allocator), ); } @@ -23,7 +23,7 @@ test "task_1_input_3" { const example_input = @embedFile("example_input_3"); try testing.expectEqual( 1930, - garden_groups.fence_cost(example_input), + garden_groups.fence_cost(example_input, std.testing.allocator), ); } @@ -32,7 +32,7 @@ test "task_2_input_1" { const example_input = @embedFile("example_input_1"); try testing.expectEqual( 80, - garden_groups.fence_cost_with_bulk_discount(example_input), + garden_groups.fence_cost_with_bulk_discount(example_input, std.testing.allocator), ); } @@ -40,7 +40,7 @@ test "task_2_input_2" { const example_input = @embedFile("example_input_2"); try testing.expectEqual( 436, - garden_groups.fence_cost_with_bulk_discount(example_input), + garden_groups.fence_cost_with_bulk_discount(example_input, std.testing.allocator), ); } @@ -48,7 +48,7 @@ test "task_2_input_3" { const example_input = @embedFile("example_input_3"); try testing.expectEqual( 1206, - garden_groups.fence_cost_with_bulk_discount(example_input), + garden_groups.fence_cost_with_bulk_discount(example_input, std.testing.allocator), ); } @@ -56,7 +56,7 @@ test "task_2_input_4" { const example_input = @embedFile("example_input_4"); try testing.expectEqual( 236, - garden_groups.fence_cost_with_bulk_discount(example_input), + garden_groups.fence_cost_with_bulk_discount(example_input, std.testing.allocator), ); } @@ -64,6 +64,6 @@ test "task_2_input_5" { const example_input = @embedFile("example_input_5"); try testing.expectEqual( 368, - garden_groups.fence_cost_with_bulk_discount(example_input), + garden_groups.fence_cost_with_bulk_discount(example_input, std.testing.allocator), ); } diff --git a/2024/13/claw_contraption/benchmarks/puzzle_benchmarks.zig b/2024/13/claw_contraption/benchmarks/puzzle_benchmarks.zig index 66ab65eb..e0bbc428 100644 --- a/2024/13/claw_contraption/benchmarks/puzzle_benchmarks.zig +++ b/2024/13/claw_contraption/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,21 @@ const claw_contraption = @import("claw_contraption"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = claw_contraption.cost_to_win_all_prizes(puzzle_input, 0) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = claw_contraption.cost_to_win_all_prizes( + puzzle_input, + 0, + allocator, + ) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = claw_contraption.cost_to_win_all_prizes(puzzle_input, 10000000000000) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = claw_contraption.cost_to_win_all_prizes( + puzzle_input, + 10000000000000, + allocator, + ) catch {}; } pub fn main() !void { diff --git a/2024/13/claw_contraption/src/claw_contraption.zig b/2024/13/claw_contraption/src/claw_contraption.zig index 41a1c2c3..a46256ac 100644 --- a/2024/13/claw_contraption/src/claw_contraption.zig +++ b/2024/13/claw_contraption/src/claw_contraption.zig @@ -14,12 +14,13 @@ const assert = std.debug.assert; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `offset`: An offset for the price coordinates. /// /// Returns: /// - Cost to win all possible prices. -pub fn cost_to_win_all_prizes(contents: string, offset: i64) !i64 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn cost_to_win_all_prizes(contents: string, offset: i64, main_allocator: Allocator) !i64 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -58,6 +59,7 @@ const ClawMachine = struct { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/13/claw_contraption/src/main.zig b/2024/13/claw_contraption/src/main.zig index a7a74ff7..f790fa60 100644 --- a/2024/13/claw_contraption/src/main.zig +++ b/2024/13/claw_contraption/src/main.zig @@ -50,11 +50,19 @@ pub fn main() !void { return; } - const result_1 = claw_contraption.cost_to_win_all_prizes(file_content, 0); + const result_1 = claw_contraption.cost_to_win_all_prizes( + file_content, + 0, + allocator, + ); try stdout.print("Mininal cost: {!}\n", .{result_1}); try bw.flush(); - const result_2 = claw_contraption.cost_to_win_all_prizes(file_content, 10000000000000); + const result_2 = claw_contraption.cost_to_win_all_prizes( + file_content, + 10000000000000, + allocator, + ); try stdout.print("Minimal cost with offset 10000000000000: {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/13/claw_contraption/tests/example_tests.zig b/2024/13/claw_contraption/tests/example_tests.zig index cefbef48..a87f6475 100644 --- a/2024/13/claw_contraption/tests/example_tests.zig +++ b/2024/13/claw_contraption/tests/example_tests.zig @@ -7,6 +7,10 @@ test "task_1" { const example_input = @embedFile("example_input"); try testing.expectEqual( 480, - claw_contraption.cost_to_win_all_prizes(example_input, 0), + claw_contraption.cost_to_win_all_prizes( + example_input, + 0, + std.testing.allocator, + ), ); } diff --git a/2024/14/restroom_redoubt/benchmarks/puzzle_benchmarks.zig b/2024/14/restroom_redoubt/benchmarks/puzzle_benchmarks.zig index 95216c0f..8d9e8407 100644 --- a/2024/14/restroom_redoubt/benchmarks/puzzle_benchmarks.zig +++ b/2024/14/restroom_redoubt/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,25 @@ const restroom_redoubt = @import("restroom_redoubt"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = restroom_redoubt.security_factor(puzzle_input, 100, 101, 103) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = restroom_redoubt.security_factor( + puzzle_input, + 100, + 101, + 103, + allocator, + ) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = restroom_redoubt.time_until_christmas_tree(puzzle_input, 101, 103, false) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = restroom_redoubt.time_until_christmas_tree( + puzzle_input, + 101, + 103, + false, + allocator, + ) catch {}; } pub fn main() !void { diff --git a/2024/14/restroom_redoubt/src/main.zig b/2024/14/restroom_redoubt/src/main.zig index 21f7b0a0..306c554a 100644 --- a/2024/14/restroom_redoubt/src/main.zig +++ b/2024/14/restroom_redoubt/src/main.zig @@ -101,6 +101,7 @@ pub fn main() !void { seconds, dim_x, dim_y, + allocator, ); try stdout.print("Security factor: {!}\n", .{result_1}); try bw.flush(); @@ -110,6 +111,7 @@ pub fn main() !void { dim_x, dim_y, print, + allocator, ); try stdout.print("Seconds until the christmas tree appears: {!}\n", .{result_2}); try bw.flush(); diff --git a/2024/14/restroom_redoubt/src/restroom_redoubt.zig b/2024/14/restroom_redoubt/src/restroom_redoubt.zig index 2abba4f6..e0509b64 100644 --- a/2024/14/restroom_redoubt/src/restroom_redoubt.zig +++ b/2024/14/restroom_redoubt/src/restroom_redoubt.zig @@ -12,11 +12,18 @@ const string = []const u8; /// - `seconds`: The amount of seconds to simulate. /// - `width`: Size of the x dimension. /// - `height`: Size of the y dimension. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - The security factor. -pub fn security_factor(contents: string, seconds: i32, width: i32, height: i32) !i32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn security_factor( + contents: string, + seconds: i32, + width: i32, + height: i32, + main_allocator: Allocator, +) !i32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -71,11 +78,18 @@ pub fn security_factor(contents: string, seconds: i32, width: i32, height: i32) /// - `contents`: Input file contents. /// - `width`: Size of the x dimension. /// - `height`: Size of the y dimension. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - The amount of seconds until the tree appears. -pub fn time_until_christmas_tree(contents: string, width: i32, height: i32, print: bool) !i32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn time_until_christmas_tree( + contents: string, + width: i32, + height: i32, + print: bool, + main_allocator: Allocator, +) !i32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); diff --git a/2024/14/restroom_redoubt/tests/example_tests.zig b/2024/14/restroom_redoubt/tests/example_tests.zig index 7553090d..85a04dc5 100644 --- a/2024/14/restroom_redoubt/tests/example_tests.zig +++ b/2024/14/restroom_redoubt/tests/example_tests.zig @@ -7,6 +7,12 @@ test "task_1" { const example_input = @embedFile("example_input"); try testing.expectEqual( 12, - restroom_redoubt.security_factor(example_input, 100, 11, 7), + restroom_redoubt.security_factor( + example_input, + 100, + 11, + 7, + std.testing.allocator, + ), ); } diff --git a/2024/15/warehouse_woes/benchmarks/puzzle_benchmarks.zig b/2024/15/warehouse_woes/benchmarks/puzzle_benchmarks.zig index b6f414b2..0ab6226b 100644 --- a/2024/15/warehouse_woes/benchmarks/puzzle_benchmarks.zig +++ b/2024/15/warehouse_woes/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ 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 {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = warehouse_woes.simulate_robot(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = warehouse_woes.simulate_robot_in_expanded_warehouse(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = warehouse_woes.simulate_robot_in_expanded_warehouse(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/15/warehouse_woes/src/main.zig b/2024/15/warehouse_woes/src/main.zig index 1d9fc0aa..9cd991bd 100644 --- a/2024/15/warehouse_woes/src/main.zig +++ b/2024/15/warehouse_woes/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const result_1 = warehouse_woes.simulate_robot(file_content); + const result_1 = warehouse_woes.simulate_robot( + file_content, + allocator, + ); try stdout.print("Sum of GPS numbers: {!}\n", .{result_1}); try bw.flush(); - const result_2 = warehouse_woes.simulate_robot_in_expanded_warehouse(file_content); + const result_2 = warehouse_woes.simulate_robot_in_expanded_warehouse( + file_content, + allocator, + ); try stdout.print("Sum of GPS numbers in expanded warehouse: {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/15/warehouse_woes/src/warehouse_woes.zig b/2024/15/warehouse_woes/src/warehouse_woes.zig index 338bad4f..fd54c7eb 100644 --- a/2024/15/warehouse_woes/src/warehouse_woes.zig +++ b/2024/15/warehouse_woes/src/warehouse_woes.zig @@ -9,11 +9,12 @@ const string = []const u8; /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Sum of GPS numbers. -pub fn simulate_robot(contents: string) !usize { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn simulate_robot(contents: string, main_allocator: Allocator) !usize { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -28,11 +29,12 @@ pub fn simulate_robot(contents: string) !usize { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Sum of GPS numbers in the expanded warehouse. -pub fn simulate_robot_in_expanded_warehouse(contents: string) !usize { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn simulate_robot_in_expanded_warehouse(contents: string, main_allocator: Allocator) !usize { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -325,6 +327,7 @@ const Warehouse = struct { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/15/warehouse_woes/tests/example_tests.zig b/2024/15/warehouse_woes/tests/example_tests.zig index 612e2062..3f78d23d 100644 --- a/2024/15/warehouse_woes/tests/example_tests.zig +++ b/2024/15/warehouse_woes/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1_input_1" { const example_input = @embedFile("example_input_1"); try testing.expectEqual( 2028, - warehouse_woes.simulate_robot(example_input), + warehouse_woes.simulate_robot(example_input, std.testing.allocator), ); } @@ -15,7 +15,7 @@ test "task_1_input_2" { const example_input = @embedFile("example_input_2"); try testing.expectEqual( 10092, - warehouse_woes.simulate_robot(example_input), + warehouse_woes.simulate_robot(example_input, std.testing.allocator), ); } @@ -24,6 +24,6 @@ test "task_2_input_2" { const example_input = @embedFile("example_input_2"); try testing.expectEqual( 9021, - warehouse_woes.simulate_robot_in_expanded_warehouse(example_input), + warehouse_woes.simulate_robot_in_expanded_warehouse(example_input, std.testing.allocator), ); } diff --git a/2024/16/reindeer_maze/benchmarks/puzzle_benchmarks.zig b/2024/16/reindeer_maze/benchmarks/puzzle_benchmarks.zig index 32cf79e3..39781106 100644 --- a/2024/16/reindeer_maze/benchmarks/puzzle_benchmarks.zig +++ b/2024/16/reindeer_maze/benchmarks/puzzle_benchmarks.zig @@ -5,13 +5,13 @@ const reindeer_maze = @import("reindeer_maze"); const puzzle_input = @embedFile("puzzle_input"); // Benchmark of part 1 -fn task_1(_: std.mem.Allocator) void { - _ = reindeer_maze.lowest_maze_score(puzzle_input) catch {}; +fn task_1(allocator: std.mem.Allocator) void { + _ = reindeer_maze.lowest_maze_score(puzzle_input, allocator) catch {}; } // Benchmark of part 2 -fn task_2(_: std.mem.Allocator) void { - _ = reindeer_maze.amount_of_viewing_positions(puzzle_input) catch {}; +fn task_2(allocator: std.mem.Allocator) void { + _ = reindeer_maze.amount_of_viewing_positions(puzzle_input, allocator) catch {}; } pub fn main() !void { diff --git a/2024/16/reindeer_maze/src/main.zig b/2024/16/reindeer_maze/src/main.zig index 9975512d..a7dd7958 100644 --- a/2024/16/reindeer_maze/src/main.zig +++ b/2024/16/reindeer_maze/src/main.zig @@ -50,11 +50,17 @@ pub fn main() !void { return; } - const result_1 = reindeer_maze.lowest_maze_score(file_content); + const result_1 = reindeer_maze.lowest_maze_score( + file_content, + allocator, + ); try stdout.print("Lowest maze score: {!}\n", .{result_1}); try bw.flush(); - const result_2 = reindeer_maze.amount_of_viewing_positions(file_content); + const result_2 = reindeer_maze.amount_of_viewing_positions( + file_content, + allocator, + ); try stdout.print("Amount of nice viewing poisitions: {!}\n", .{result_2}); try bw.flush(); } diff --git a/2024/16/reindeer_maze/src/reindeer_maze.zig b/2024/16/reindeer_maze/src/reindeer_maze.zig index f90e8a0d..04a4a5d2 100644 --- a/2024/16/reindeer_maze/src/reindeer_maze.zig +++ b/2024/16/reindeer_maze/src/reindeer_maze.zig @@ -13,11 +13,12 @@ const dijkstra = @import("./dijkstra.zig"); /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Cost of the shortest path. -pub fn lowest_maze_score(contents: string) !u32 { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn lowest_maze_score(contents: string, main_allocator: Allocator) !u32 { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -40,11 +41,12 @@ pub fn lowest_maze_score(contents: string) !u32 { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// /// Returns: /// - Number of tiles that are part of any shortest path. -pub fn amount_of_viewing_positions(contents: string) !usize { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); +pub fn amount_of_viewing_positions(contents: string, main_allocator: Allocator) !usize { + var arena = std.heap.ArenaAllocator.init(main_allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -222,6 +224,7 @@ const Maze = struct { /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: diff --git a/2024/16/reindeer_maze/tests/example_tests.zig b/2024/16/reindeer_maze/tests/example_tests.zig index 1c7b9118..5b27cb41 100644 --- a/2024/16/reindeer_maze/tests/example_tests.zig +++ b/2024/16/reindeer_maze/tests/example_tests.zig @@ -7,7 +7,7 @@ test "task_1_input_1" { const example_input = @embedFile("example_input_1"); try testing.expectEqual( 7036, - reindeer_maze.lowest_maze_score(example_input), + reindeer_maze.lowest_maze_score(example_input, std.testing.allocator), ); } @@ -15,7 +15,7 @@ test "task_1_input_2" { const example_input = @embedFile("example_input_2"); try testing.expectEqual( 11048, - reindeer_maze.lowest_maze_score(example_input), + reindeer_maze.lowest_maze_score(example_input, std.testing.allocator), ); } @@ -24,7 +24,7 @@ test "task_2_input_1" { const example_input = @embedFile("example_input_1"); try testing.expectEqual( 45, - reindeer_maze.amount_of_viewing_positions(example_input), + reindeer_maze.amount_of_viewing_positions(example_input, std.testing.allocator), ); } @@ -32,6 +32,6 @@ test "task_2_input_2" { const example_input = @embedFile("example_input_2"); try testing.expectEqual( 64, - reindeer_maze.amount_of_viewing_positions(example_input), + reindeer_maze.amount_of_viewing_positions(example_input, std.testing.allocator), ); } diff --git a/2024/17/chronospatial_computer/src/chronospatial_computer.zig b/2024/17/chronospatial_computer/src/chronospatial_computer.zig index 59b2a96d..e8ebd51c 100644 --- a/2024/17/chronospatial_computer/src/chronospatial_computer.zig +++ b/2024/17/chronospatial_computer/src/chronospatial_computer.zig @@ -230,6 +230,7 @@ fn program_to_string(program: ArrayList(Instruction), allocator: Allocator) !str /// /// Arguments: /// - `contents`: Input file contents. +/// - `main_allocator`: Base allocator for everything. /// - `allocator`: Allocator for the containers. /// /// Returns: