aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2023-12-18 08:13:24 +0000
committerMartin Ashby <martin@ashbysoft.com>2023-12-18 08:13:24 +0000
commit0f7b5ffbb27270c628609884cb6b932f025f973d (patch)
tree250f93837ad3bc40ee199f9feca1a70ad7949f6b
parentd6ef49af270183a29776def2f1c3178fa14bc5aa (diff)
downloadaoc2023-main.tar.gz
aoc2023-main.tar.bz2
aoc2023-main.tar.xz
aoc2023-main.zip
day 11 pt2HEADmain
-rw-r--r--day11.zig17
1 files changed, 15 insertions, 2 deletions
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 =
\\...#......