-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay12.cs
More file actions
110 lines (98 loc) · 3.38 KB
/
Day12.cs
File metadata and controls
110 lines (98 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System.Diagnostics;
using System;
namespace _2025._12
{
public sealed class Day12 : Base
{
List<HashSet<(int, int)>> _presents = [];
List<(int rows, int cols, int[] presents)> _christmasTrees = [];
public Day12(bool example) : base(example)
{
Day = "12";
}
private void ParseInput()
{
string[] input = ReadInput();
for(int i = 0; i < input.Length; i++)
{
if (string.IsNullOrWhiteSpace(input[i]))
{
continue;
}
if(input[i].Contains("x"))
{
string[] split = input[i].Split(": ");
int splitter = split[0].IndexOf("x", StringComparison.Ordinal);
_christmasTrees.Add((
int.Parse(split[0][(splitter+1)..]),
int.Parse(split[0][..splitter]),
split[1].Split(" ").Select(int.Parse).ToArray())
);
continue;
}
if (input[i][^1] != ':')
{
continue;
}
_presents.Add([]);
i++;
for(int presentStart = i; !string.IsNullOrWhiteSpace(input[i]); i++)
{
_presents[^1].UnionWith(input[i]
.Select((x, index) => (x, index))
.Where(x => x.x == '#')
.Select(x => (i - presentStart, x.index))
.ToHashSet()
);
}
}
}
private void PrintInput()
{
foreach ((var present, int index) in _presents.Select((x, i) => (x, i)))
{
Console.WriteLine($"{index}: ");
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 3; col++)
{
if (present.Contains((row, col)))
{
Console.Write("#");
}
else
{
Console.Write(".");
}
}
Console.WriteLine();
}
Console.WriteLine();
}
foreach (var christmasTree in _christmasTrees)
{
Console.WriteLine($"{christmasTree.rows}x{christmasTree.cols}: {string.Join(" ", christmasTree.presents.Select(x => x.ToString()))}");
}
}
public override object PartOne()
{
ParseInput();
int numFitting = 0;
foreach ((int rows, int cols, int[] presents) in _christmasTrees)
{
if (rows * cols < 9 * presents.Sum())
{
Console.WriteLine($"Definitely not enough space! {presents.Sum()*9} {rows}x{cols}: {string.Join(" ", presents.Select(x => x.ToString()))}");
continue;
}
// TODO CHECK?
numFitting++;
}
return numFitting;
}
public override object PartTwo()
{
return "";
}
}
}