From 0f7b5ffbb27270c628609884cb6b932f025f973d Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Mon, 18 Dec 2023 08:13:24 +0000 Subject: day 11 pt2 --- day11.zig | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'day11.zig') diff --git a/day11.zig b/day11.zig index bcb5c2a..190c860 100644 --- a/day11.zig +++ b/day11.zig @@ -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 = \\...#...... -- cgit v1.2.3-ZIG