Finish day12, part 1
This feels like cheating
This commit is contained in:
parent
f088a5a21a
commit
0633ee80a9
1 changed files with 41 additions and 40 deletions
|
|
@ -3,42 +3,42 @@ const std = @import("std");
|
||||||
pub const title = "Day 12: Christmas Tree Farm";
|
pub const title = "Day 12: Christmas Tree Farm";
|
||||||
|
|
||||||
pub fn run(allocator: std.mem.Allocator) !void {
|
pub fn run(allocator: std.mem.Allocator) !void {
|
||||||
//const input = @embedFile("./input/day12.txt");
|
const input = @embedFile("./input/day12.txt");
|
||||||
const input =
|
//const input =
|
||||||
\\0:
|
// \\0:
|
||||||
\\###
|
// \\###
|
||||||
\\##.
|
// \\##.
|
||||||
\\##.
|
// \\##.
|
||||||
\\
|
// \\
|
||||||
\\1:
|
// \\1:
|
||||||
\\###
|
// \\###
|
||||||
\\##.
|
// \\##.
|
||||||
\\.##
|
// \\.##
|
||||||
\\
|
// \\
|
||||||
\\2:
|
// \\2:
|
||||||
\\.##
|
// \\.##
|
||||||
\\###
|
// \\###
|
||||||
\\##.
|
// \\##.
|
||||||
\\
|
// \\
|
||||||
\\3:
|
// \\3:
|
||||||
\\##.
|
// \\##.
|
||||||
\\###
|
// \\###
|
||||||
\\##.
|
// \\##.
|
||||||
\\
|
// \\
|
||||||
\\4:
|
// \\4:
|
||||||
\\###
|
// \\###
|
||||||
\\#..
|
// \\#..
|
||||||
\\###
|
// \\###
|
||||||
\\
|
// \\
|
||||||
\\5:
|
// \\5:
|
||||||
\\###
|
// \\###
|
||||||
\\.#.
|
// \\.#.
|
||||||
\\###
|
// \\###
|
||||||
\\
|
// \\
|
||||||
\\4x4: 0 0 0 0 2 0
|
// \\4x4: 0 0 0 0 2 0
|
||||||
\\12x5: 1 0 1 0 2 2
|
// \\12x5: 1 0 1 0 2 2
|
||||||
\\12x5: 1 0 1 0 3 2
|
// \\12x5: 1 0 1 0 3 2
|
||||||
;
|
// ;
|
||||||
|
|
||||||
var lines = std.mem.tokenizeScalar(u8, input, '\n');
|
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 (semicolon_pos != 0) {
|
||||||
if (x_pos) |p| {
|
if (x_pos) |p| {
|
||||||
// region
|
// region
|
||||||
const width = try std.fmt.parseUnsigned(u8, line[0..p], 10);
|
const width = try std.fmt.parseUnsigned(usize, line[0..p], 10);
|
||||||
const height = try std.fmt.parseUnsigned(u8, line[p + 1..semicolon_pos], 10);
|
const height = try std.fmt.parseUnsigned(usize, line[p + 1..semicolon_pos], 10);
|
||||||
|
|
||||||
var required_presents: std.ArrayList(u8) = .empty;
|
var required_presents: std.ArrayList(u8) = .empty;
|
||||||
defer required_presents.deinit(allocator);
|
defer required_presents.deinit(allocator);
|
||||||
|
|
@ -114,6 +114,7 @@ pub fn run(allocator: std.mem.Allocator) !void {
|
||||||
var accumulator: usize = 0;
|
var accumulator: usize = 0;
|
||||||
|
|
||||||
for (regions.items) |region| {
|
for (regions.items) |region| {
|
||||||
|
std.debug.print("{f}\n", .{region});
|
||||||
var area_needed: usize = 0;
|
var area_needed: usize = 0;
|
||||||
for (region.required_presents, 0..) |amount, i| {
|
for (region.required_presents, 0..) |amount, i| {
|
||||||
area_needed += amount * presents.items[i].area();
|
area_needed += amount * presents.items[i].area();
|
||||||
|
|
@ -167,8 +168,8 @@ const Present = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
const Region = struct {
|
const Region = struct {
|
||||||
width: u8,
|
width: usize,
|
||||||
height: u8,
|
height: usize,
|
||||||
required_presents: []u8,
|
required_presents: []u8,
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue