This is terrible, but it's Christmas and I don't want to solve this intense graph theory problem right now. I fed the parsed graph into graphviz so I could see where the connections were, then had the code sever them and calculate the independent graph sizes.

Maybe I'll find a real solve for this later...but probably not.
This commit is contained in:
2023-12-25 17:06:20 -06:00
parent 42d5939428
commit 166281cf7c
4 changed files with 1392 additions and 0 deletions

View File

@ -77,6 +77,8 @@
<EmbeddedResource Include="inputs\21a.txt" />
<EmbeddedResource Include="inputs\24.txt" />
<EmbeddedResource Include="inputs\24a.txt" />
<EmbeddedResource Include="inputs\25.txt" />
<EmbeddedResource Include="inputs\25a.txt" />
<None Remove="inputs\22.txt" />
<EmbeddedResource Include="inputs\22.txt" />
<None Remove="inputs\22a.txt" />

1262
inputs/25.txt Normal file

File diff suppressed because it is too large Load Diff

13
inputs/25a.txt Normal file
View File

@ -0,0 +1,13 @@
jqt: rhn xhk nvd
rsh: frs pzl lsr
xhk: hfx
cmg: qnr nvd lhk bvb
rhn: xhk bvb hfx
bvb: xhk hfx
pzl: lsr hfx nvd
qnr: nvd
ntq: jqt hfx bvb xhk
nvd: lhk
lsr: lhk
rzs: qnr cmg lsr rsh
frs: qnr lhk lsr

115
src/25.cs Normal file
View File

@ -0,0 +1,115 @@
using aoc2023.Util;
namespace aoc2023;
internal class Day25 : Day
{
private Dictionary<string, List<string>> connections = [];
internal override void Parse()
{
var lines = Util.Parsing.ReadAllLines($"{GetDay()}");
foreach (var line in lines)
{
var split = line.Split(": ");
var right = split[1].Split(' ', StringSplitOptions.RemoveEmptyEntries);
connections.TryAdd(split[0], []);
foreach (var r in right)
{
connections[split[0]].AddUnique(r);
connections.TryAdd(r, []);
connections[r].AddUnique(split[0]);
}
}
// Logger.LogLine("graph G {");
// foreach (var c in connections)
// {
// Logger.LogLine($"{c.Key} -- {{ {string.Join(' ', c.Value)} }}");
// }
// Logger.LogLine("}");
}
internal override string Part1()
{
var br = connections.ToDictionary();
foreach (var b in br)
{
br[b.Key] = [..b.Value];
if (b.Key == "nqq")
{
br[b.Key].Remove("pxp");
}
if (b.Key == "pxp")
{
br[b.Key].Remove("nqq");
}
if (b.Key == "jxb")
{
br[b.Key].Remove("ksq");
}
if (b.Key == "ksq")
{
br[b.Key].Remove("jxb");
}
if (b.Key == "kns")
{
br[b.Key].Remove("dct");
}
if (b.Key == "dct")
{
br[b.Key].Remove("kns");
}
}
List<string> h1 = ["pxp", "dct", "ksq"];
List<string> h2 = ["nqq", "jxb", "kns"];
bool bfound = false;
while (!bfound)
{
bfound = true;
int c = h1.Count;
for (int i = 0; i < c; i++)
{
foreach (var n in br[h1[i]])
{
if (!h1.Contains(n))
{
bfound = false;
h1.Add(n);
}
}
}
}
bfound = false;
while (!bfound)
{
bfound = true;
var c = h2.Count;
for (int i = 0; i < c; i++)
{
foreach (var n in br[h2[i]])
{
if (!h2.Contains(n))
{
bfound = false;
h2.Add(n);
}
}
}
}
return $"{h1.Count} * {h2.Count} = <+white>{h1.Count * h2.Count}";
}
internal override string Part2()
{
return $"<red>M<green>e<red>r<green>r<red>y <green>C<red>h<green>r<red>i<green>s<red>t<green>m<red>a<green>s<red>!";
}
}