Finish day12, part 1

This feels like cheating
This commit is contained in:
ktkk 2025-12-12 22:07:05 +00:00
parent f088a5a21a
commit 0633ee80a9

View file

@ -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();