diff options
author | Martin Ashby <martin@ashbysoft.com> | 2023-12-18 08:13:24 +0000 |
---|---|---|
committer | Martin Ashby <martin@ashbysoft.com> | 2023-12-18 08:13:24 +0000 |
commit | 0f7b5ffbb27270c628609884cb6b932f025f973d (patch) | |
tree | 250f93837ad3bc40ee199f9feca1a70ad7949f6b /day11.zig | |
parent | d6ef49af270183a29776def2f1c3178fa14bc5aa (diff) | |
download | aoc2023-main.tar.gz aoc2023-main.tar.bz2 aoc2023-main.tar.xz aoc2023-main.zip |
Diffstat (limited to 'day11.zig')
-rw-r--r-- | day11.zig | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -2,6 +2,7 @@ const std = @import("std"); pub fn main() !void { try std.fmt.format(std.io.getStdOut().writer(), "day 11 pt1: {}\n", .{try solve_pt1(std.heap.page_allocator, puzzle_input)}); + try std.fmt.format(std.io.getStdOut().writer(), "day 11 pt2: {}\n", .{try solve_pt2(std.heap.page_allocator, puzzle_input)}); } const Coord = struct { @@ -14,6 +15,12 @@ inline fn get(grid: []const u8, width: usize, x: usize, y: usize) u8 { } fn solve_pt1(a: std.mem.Allocator, input: []const u8) !u64 { + return solve(a, input, 2); +} +fn solve_pt2(a: std.mem.Allocator, input: []const u8) !u64 { + return solve(a, input, 1000000); +} +fn solve(a: std.mem.Allocator, input: []const u8, multiplier: usize) !u64 { const width: usize = std.mem.indexOfScalar(u8, input, '\n') orelse return error.BadInput; const height: usize = (input.len / width + 1) - 1; // std.log.warn("width {} height {}", .{width, height}); @@ -34,7 +41,7 @@ fn solve_pt1(a: std.mem.Allocator, input: []const u8) !u64 { } } if (allspace) { - x_adj += 1; + x_adj += (multiplier-1); } x_adjust[x] = x_adj; } @@ -48,7 +55,7 @@ fn solve_pt1(a: std.mem.Allocator, input: []const u8) !u64 { } } if (allspace) { - y_adj += 1; + y_adj += (multiplier-1); } y_adjust[y] = y_adj; } @@ -79,6 +86,12 @@ fn solve_pt1(a: std.mem.Allocator, input: []const u8) !u64 { test "pt1" { try std.testing.expectEqual(@as(u64, 374), try solve_pt1(std.testing.allocator, test_input)); } +test "pt2" { + try std.testing.expectEqual(@as(u64, 1030), try solve(std.testing.allocator, test_input, 10)); +} +test "pt2_2" { + try std.testing.expectEqual(@as(u64, 8410), try solve(std.testing.allocator, test_input, 100)); +} const test_input = \\...#...... |