From 0633ee80a9450b8a6c6cd2c93b122cef7b2a5f86 Mon Sep 17 00:00:00 2001 From: ktkk Date: Fri, 12 Dec 2025 22:07:05 +0000 Subject: [PATCH] Finish day12, part 1 This feels like cheating --- src/days/day12.zig | 81 +++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/days/day12.zig b/src/days/day12.zig index 26d586b..354fe56 100644 --- a/src/days/day12.zig +++ b/src/days/day12.zig @@ -3,42 +3,42 @@ const std = @import("std"); pub const title = "Day 12: Christmas Tree Farm"; pub fn run(allocator: std.mem.Allocator) !void { - //const input = @embedFile("./input/day12.txt"); - const input = - \\0: - \\### - \\##. - \\##. - \\ - \\1: - \\### - \\##. - \\.## - \\ - \\2: - \\.## - \\### - \\##. - \\ - \\3: - \\##. - \\### - \\##. - \\ - \\4: - \\### - \\#.. - \\### - \\ - \\5: - \\### - \\.#. - \\### - \\ - \\4x4: 0 0 0 0 2 0 - \\12x5: 1 0 1 0 2 2 - \\12x5: 1 0 1 0 3 2 - ; + const input = @embedFile("./input/day12.txt"); + //const input = + // \\0: + // \\### + // \\##. + // \\##. + // \\ + // \\1: + // \\### + // \\##. + // \\.## + // \\ + // \\2: + // \\.## + // \\### + // \\##. + // \\ + // \\3: + // \\##. + // \\### + // \\##. + // \\ + // \\4: + // \\### + // \\#.. + // \\### + // \\ + // \\5: + // \\### + // \\.#. + // \\### + // \\ + // \\4x4: 0 0 0 0 2 0 + // \\12x5: 1 0 1 0 2 2 + // \\12x5: 1 0 1 0 3 2 + // ; var lines = std.mem.tokenizeScalar(u8, input, '\n'); @@ -69,8 +69,8 @@ pub fn run(allocator: std.mem.Allocator) !void { if (semicolon_pos != 0) { if (x_pos) |p| { // region - const width = try std.fmt.parseUnsigned(u8, line[0..p], 10); - const height = try std.fmt.parseUnsigned(u8, line[p + 1..semicolon_pos], 10); + const width = try std.fmt.parseUnsigned(usize, line[0..p], 10); + const height = try std.fmt.parseUnsigned(usize, line[p + 1..semicolon_pos], 10); var required_presents: std.ArrayList(u8) = .empty; defer required_presents.deinit(allocator); @@ -114,6 +114,7 @@ pub fn run(allocator: std.mem.Allocator) !void { var accumulator: usize = 0; for (regions.items) |region| { + std.debug.print("{f}\n", .{region}); var area_needed: usize = 0; for (region.required_presents, 0..) |amount, i| { area_needed += amount * presents.items[i].area(); @@ -167,8 +168,8 @@ const Present = struct { }; const Region = struct { - width: u8, - height: u8, + width: usize, + height: usize, required_presents: []u8, const Self = @This();