mirror of
https://github.com/farcasclaudiu/advent_of_code_2022.git
synced 2026-06-22 05:01:20 +03:00
first part of day16 un-optimal
This commit is contained in:
Vendored
+2
-2
@@ -10,9 +10,9 @@
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// If you have changed target frameworks, make sure to update the program path.
|
||||
"program": "${workspaceFolder}/day15/day15/bin/Debug/net6.0/day15.dll",
|
||||
"program": "${workspaceFolder}/day16/day16/bin/Debug/net6.0/day16.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/day15/day15",
|
||||
"cwd": "${workspaceFolder}/day16/day16",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false
|
||||
|
||||
Vendored
+3
-3
@@ -7,7 +7,7 @@
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/day15/day15/day15.csproj",
|
||||
"${workspaceFolder}/day16/day16/day16.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
@@ -19,7 +19,7 @@
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/day15/day15/day15.csproj",
|
||||
"${workspaceFolder}/day16/day16/day16.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
@@ -33,7 +33,7 @@
|
||||
"watch",
|
||||
"run",
|
||||
"--project",
|
||||
"${workspaceFolder}/day15/day15/day15.csproj"
|
||||
"${workspaceFolder}/day16/day16/day16.csproj"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
|
||||
@@ -87,6 +87,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day14", "day14\day14\day14.
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day14.test", "day14\day14.test\day14.test.csproj", "{82F6593B-3354-4246-B18E-B25A9DDEDBCC}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day15", "day15", "{8440BDDD-87D2-4E1F-BFBE-06966503606C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day15", "day15\day15\day15.csproj", "{30222749-97A6-4B32-99AD-BE6EFD8586DD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day15.test", "day15\day15.test\day15.test.csproj", "{9712599F-6FA9-45A8-8D96-7EEEF954DFF2}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day16", "day16", "{E56226D6-D528-469B-9514-80704588ACAE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day16", "day16\day16\day16.csproj", "{FAE1D8C0-697D-4B03-B3D5-14C58D1EE00B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day16.test", "day16\day16.test\day16.test.csproj", "{E4E64EA3-A601-4996-A21A-96B1DC01A18E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -208,6 +220,22 @@ Global
|
||||
{82F6593B-3354-4246-B18E-B25A9DDEDBCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{82F6593B-3354-4246-B18E-B25A9DDEDBCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{82F6593B-3354-4246-B18E-B25A9DDEDBCC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{30222749-97A6-4B32-99AD-BE6EFD8586DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{30222749-97A6-4B32-99AD-BE6EFD8586DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{30222749-97A6-4B32-99AD-BE6EFD8586DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{30222749-97A6-4B32-99AD-BE6EFD8586DD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9712599F-6FA9-45A8-8D96-7EEEF954DFF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9712599F-6FA9-45A8-8D96-7EEEF954DFF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9712599F-6FA9-45A8-8D96-7EEEF954DFF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9712599F-6FA9-45A8-8D96-7EEEF954DFF2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FAE1D8C0-697D-4B03-B3D5-14C58D1EE00B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FAE1D8C0-697D-4B03-B3D5-14C58D1EE00B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FAE1D8C0-697D-4B03-B3D5-14C58D1EE00B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FAE1D8C0-697D-4B03-B3D5-14C58D1EE00B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E4E64EA3-A601-4996-A21A-96B1DC01A18E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E4E64EA3-A601-4996-A21A-96B1DC01A18E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E4E64EA3-A601-4996-A21A-96B1DC01A18E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E4E64EA3-A601-4996-A21A-96B1DC01A18E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{DD750DA9-951E-4CF6-91A0-629B65FF6AD6} = {E7C08291-5975-4F77-BA54-06CAF8EC64EE}
|
||||
@@ -238,5 +266,9 @@ Global
|
||||
{A7209996-5CB1-4D1F-AFC4-F50EE465FD98} = {07E3D4B8-F361-4467-B27C-42B6D5427988}
|
||||
{8DF3A058-7F98-4F2F-9601-32BE3312857C} = {94CABFE2-1106-44CA-9722-54E3C2A77F21}
|
||||
{82F6593B-3354-4246-B18E-B25A9DDEDBCC} = {94CABFE2-1106-44CA-9722-54E3C2A77F21}
|
||||
{30222749-97A6-4B32-99AD-BE6EFD8586DD} = {8440BDDD-87D2-4E1F-BFBE-06966503606C}
|
||||
{9712599F-6FA9-45A8-8D96-7EEEF954DFF2} = {8440BDDD-87D2-4E1F-BFBE-06966503606C}
|
||||
{FAE1D8C0-697D-4B03-B3D5-14C58D1EE00B} = {E56226D6-D528-469B-9514-80704588ACAE}
|
||||
{E4E64EA3-A601-4996-A21A-96B1DC01A18E} = {E56226D6-D528-469B-9514-80704588ACAE}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace day16.test;
|
||||
using FluentAssertions;
|
||||
public class UnitTestProblem
|
||||
{
|
||||
[Fact]
|
||||
public void TestProblem1()
|
||||
{
|
||||
var problem = new Problem();
|
||||
problem.ResolvePart1("testdata.txt");
|
||||
|
||||
problem.Result1.Should().Be("1651");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestProblem2()
|
||||
{
|
||||
var problem = new Problem();
|
||||
problem.ResolvePart2("testdata.txt");
|
||||
|
||||
problem.Result2.Should().Be("1707");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
global using Xunit;
|
||||
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../day16/day16.csproj" />
|
||||
<Content Include="testdata.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.8.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,10 @@
|
||||
Valve AA has flow rate=0; tunnels lead to valves DD, II, BB
|
||||
Valve BB has flow rate=13; tunnels lead to valves CC, AA
|
||||
Valve CC has flow rate=2; tunnels lead to valves DD, BB
|
||||
Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE
|
||||
Valve EE has flow rate=3; tunnels lead to valves FF, DD
|
||||
Valve FF has flow rate=0; tunnels lead to valves EE, GG
|
||||
Valve GG has flow rate=0; tunnels lead to valves FF, HH
|
||||
Valve HH has flow rate=22; tunnel leads to valve GG
|
||||
Valve II has flow rate=0; tunnels lead to valves AA, JJ
|
||||
Valve JJ has flow rate=21; tunnel leads to valve II
|
||||
@@ -0,0 +1,201 @@
|
||||
namespace day16;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
|
||||
public class Problem
|
||||
{
|
||||
public string Result1 { get; set; }
|
||||
public string Result2 { get; set; }
|
||||
|
||||
|
||||
|
||||
Regex rg = new Regex(
|
||||
"Valve (?<valve>[A-Z]+) has flow rate=(?<flow>[0-9]+); tunnels? leads? to valves? (?<leads>.+)"
|
||||
);
|
||||
|
||||
|
||||
private int totalMinutes = 30;
|
||||
private int previousPressure = 0;
|
||||
|
||||
public static int MaxPressure;
|
||||
public void ResolvePart1(string arg)
|
||||
{
|
||||
var lines = File.ReadAllLines(arg);
|
||||
|
||||
List<Valve> lstValves = new List<Valve>();
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var match = rg.Match(line);
|
||||
if (match.Success)
|
||||
{
|
||||
var valve = match.Groups["valve"].Captures[0].Value;
|
||||
var flow = match.Groups["flow"].Captures[0].Value;
|
||||
var leads = match.Groups["leads"].Captures[0].Value;
|
||||
lstValves.Add(new Valve(valve, flow, leads));
|
||||
}
|
||||
}
|
||||
|
||||
var machine = new Machine
|
||||
(
|
||||
totalMinutes, //max minutes
|
||||
1, // current minute
|
||||
lstValves, //valves
|
||||
new(), //open valves
|
||||
0, //total flow
|
||||
"AA", //current valve,
|
||||
"m" + "AA" //first action
|
||||
);
|
||||
machine.MoveList = new List<string>();
|
||||
var maxFlow = machine.MoveNext();
|
||||
|
||||
Result1 = maxFlow.ToString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void ResolvePart2(string arg)
|
||||
{
|
||||
var lines = File.ReadAllLines(arg);
|
||||
|
||||
|
||||
Result2 = "x".ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Machine
|
||||
{
|
||||
private Machine() { }
|
||||
|
||||
public Machine(int maxMinutes,
|
||||
int currentMinute,
|
||||
List<Valve> valves,
|
||||
List<Valve> openValves,
|
||||
int totalFlow,
|
||||
string currentValve,
|
||||
string path)
|
||||
{
|
||||
MaxMinutes = maxMinutes;
|
||||
CurrentMinute = currentMinute;
|
||||
Valves = new List<Valve>(valves);
|
||||
OpenValves = new List<Valve>(openValves);
|
||||
TotalFlow = totalFlow;
|
||||
CurrentValve = currentValve;
|
||||
Path = path;
|
||||
}
|
||||
|
||||
public int MaxMinutes { get; }
|
||||
public int CurrentMinute { get; internal set; }
|
||||
public List<Valve> Valves { get; }
|
||||
public List<Valve> OpenValves { get; }
|
||||
public int TotalFlow { get; }
|
||||
public string CurrentValve { get; }
|
||||
public string Path { get; }
|
||||
public List<string> MoveList { get; set; } = new List<string>();
|
||||
|
||||
public int MoveNext()
|
||||
{
|
||||
// System.Console.WriteLine($"{TotalFlow} : {Path}");
|
||||
var result = TotalFlow;
|
||||
if (CurrentMinute < MaxMinutes)
|
||||
{
|
||||
var unopened = Valves.Count(v => v.Flow > 0) - OpenValves.Count;
|
||||
if (unopened > 0)
|
||||
{
|
||||
var valve = Valves.First(v => v.Label == CurrentValve);
|
||||
|
||||
//open current valve if possible
|
||||
if (valve.Flow > 0 && !OpenValves.Contains(valve))
|
||||
{
|
||||
var cOV = new List<Valve>(OpenValves);
|
||||
cOV.Add(valve);
|
||||
var childMachine = new Machine(
|
||||
MaxMinutes,
|
||||
CurrentMinute + 1,
|
||||
Valves,
|
||||
cOV,
|
||||
TotalFlow + (MaxMinutes - CurrentMinute) * valve.Flow,
|
||||
valve.Label,
|
||||
Path + ",o" + valve.Label
|
||||
);
|
||||
result = Math.Max(result, childMachine.MoveNext());
|
||||
}
|
||||
|
||||
var maxDepth = Valves.Count(v => v.Flow == 0) + unopened;//optimization
|
||||
if (MoveList.Count < maxDepth)
|
||||
{
|
||||
// process moving next first
|
||||
foreach (var tunnel in valve.Tunnels)
|
||||
{
|
||||
if (!this.MoveList.Contains(tunnel))
|
||||
{
|
||||
var childMachine = new Machine(
|
||||
MaxMinutes,
|
||||
CurrentMinute + 1,
|
||||
Valves,
|
||||
OpenValves,
|
||||
TotalFlow,
|
||||
tunnel,
|
||||
Path + ",m" + tunnel
|
||||
);
|
||||
childMachine.MoveList = new List<string>(this.MoveList);
|
||||
childMachine.MoveList.Add(tunnel);
|
||||
var result2 = childMachine.MoveNext();
|
||||
result = Math.Max(result, result2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (CurrentMinute == MaxMinutes)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"impossible situation: {CurrentMinute}");
|
||||
}
|
||||
// if (result > Problem.MaxPressure)
|
||||
// {
|
||||
// Problem.MaxPressure = result;
|
||||
// System.Console.WriteLine($"max: {result} path: {this.Path}");
|
||||
// //max: 2087 path: mAA,mPE,mWW,mDY,mYI,oYI,mMZ,mUA,oUA,mKY,mAW,oAW,mYZ,mEL,oEL,mRD,mOY,oOY,mVO,mFL,oFL,mFH,mWZ,mEG,oEG,mZP,mMC,mXY,oXY
|
||||
// }
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class Valve
|
||||
{
|
||||
public Valve(string label, string flow, string tunnels)
|
||||
{
|
||||
Label = label;
|
||||
Flow = int.Parse(flow);
|
||||
this.Tunnels = tunnels.Split(",", StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
}
|
||||
|
||||
public string Label { get; }
|
||||
public int Flow { get; }
|
||||
|
||||
public List<string> Tunnels { get; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"valve: {Label} flow {Flow} tunnels {string.Join(',', Tunnels)}";
|
||||
}
|
||||
|
||||
|
||||
public Valve GetBestValveToOpen(Stack<Valve> openedValves, List<Valve> allvalves)
|
||||
{
|
||||
var candidates = this.Tunnels
|
||||
.Select(t => allvalves.Find(v => v.Label == t && !openedValves.Contains(v)))
|
||||
.Where(v => v != null && ((v.Flow > (2 * this.Flow)) || (this.Flow == 0 && v.Flow == 0)))
|
||||
.OrderByDescending(v => v.Flow).ToList();
|
||||
if (candidates.Count > 0)
|
||||
{
|
||||
return candidates.First();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace day16;
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var inputFile = "testdata.txt";
|
||||
// var inputFile = "input.txt";
|
||||
|
||||
var problem = new Problem();
|
||||
|
||||
problem.ResolvePart1(inputFile);
|
||||
System.Console.WriteLine($"Result1: {problem.Result1}");
|
||||
// test 1651
|
||||
// input 2087
|
||||
|
||||
// problem.ResolvePart2(inputFile);
|
||||
// System.Console.WriteLine($"Result2: {problem.Result2}");
|
||||
// test 1707
|
||||
// input ????
|
||||
|
||||
//TODO - improve by applying Floyd Warshall algorithm
|
||||
// inspire from https://github.com/Bpendragon/AdventOfCodeCSharp/blob/9fd66/AdventOfCode/Solutions/Year2022/Day16-Solution.cs
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,57 @@
|
||||
Valve EG has flow rate=21; tunnels lead to valves WZ, OF, ZP, QD
|
||||
Valve OR has flow rate=0; tunnels lead to valves QD, CR
|
||||
Valve VO has flow rate=0; tunnels lead to valves FL, OY
|
||||
Valve BV has flow rate=0; tunnels lead to valves AA, KK
|
||||
Valve OF has flow rate=0; tunnels lead to valves EJ, EG
|
||||
Valve YZ has flow rate=0; tunnels lead to valves EL, AW
|
||||
Valve EL has flow rate=16; tunnels lead to valves YZ, RD
|
||||
Valve EJ has flow rate=0; tunnels lead to valves YI, OF
|
||||
Valve FM has flow rate=0; tunnels lead to valves VX, FX
|
||||
Valve FL has flow rate=22; tunnels lead to valves VO, FH
|
||||
Valve QD has flow rate=0; tunnels lead to valves OR, EG
|
||||
Valve XC has flow rate=0; tunnels lead to valves UA, GV
|
||||
Valve WZ has flow rate=0; tunnels lead to valves FH, EG
|
||||
Valve AT has flow rate=0; tunnels lead to valves FX, OZ
|
||||
Valve MZ has flow rate=0; tunnels lead to valves UA, YI
|
||||
Valve WI has flow rate=0; tunnels lead to valves OH, WW
|
||||
Valve YD has flow rate=0; tunnels lead to valves OZ, WW
|
||||
Valve QX has flow rate=0; tunnels lead to valves OY, YI
|
||||
Valve AA has flow rate=0; tunnels lead to valves BV, ZE, PE, XL
|
||||
Valve VX has flow rate=0; tunnels lead to valves FM, GQ
|
||||
Valve VN has flow rate=0; tunnels lead to valves TU, OQ
|
||||
Valve RD has flow rate=0; tunnels lead to valves OY, EL
|
||||
Valve QR has flow rate=0; tunnels lead to valves QQ, OZ
|
||||
Valve CD has flow rate=0; tunnels lead to valves WW, RJ
|
||||
Valve VA has flow rate=20; tunnel leads to valve DE
|
||||
Valve RJ has flow rate=0; tunnels lead to valves CR, CD
|
||||
Valve UA has flow rate=19; tunnels lead to valves XC, MZ, KY
|
||||
Valve WW has flow rate=4; tunnels lead to valves YD, PE, WI, DY, CD
|
||||
Valve MC has flow rate=0; tunnels lead to valves ZP, XY
|
||||
Valve XY has flow rate=24; tunnel leads to valve MC
|
||||
Valve FH has flow rate=0; tunnels lead to valves FL, WZ
|
||||
Valve DE has flow rate=0; tunnels lead to valves VA, FX
|
||||
Valve DY has flow rate=0; tunnels lead to valves WW, YI
|
||||
Valve FX has flow rate=14; tunnels lead to valves DE, FM, AT, OQ
|
||||
Valve UU has flow rate=0; tunnels lead to valves AR, AW
|
||||
Valve OY has flow rate=13; tunnels lead to valves RD, VO, AR, GV, QX
|
||||
Valve CS has flow rate=0; tunnels lead to valves MG, OZ
|
||||
Valve KY has flow rate=0; tunnels lead to valves UA, AW
|
||||
Valve KK has flow rate=0; tunnels lead to valves BV, TU
|
||||
Valve GQ has flow rate=18; tunnel leads to valve VX
|
||||
Valve ZV has flow rate=0; tunnels lead to valves YI, LS
|
||||
Valve QQ has flow rate=0; tunnels lead to valves CR, QR
|
||||
Valve AW has flow rate=25; tunnels lead to valves YZ, KY, UU
|
||||
Valve OH has flow rate=0; tunnels lead to valves WI, TU
|
||||
Valve CR has flow rate=8; tunnels lead to valves OR, ZE, RJ, LS, QQ
|
||||
Valve TU has flow rate=7; tunnels lead to valves MG, VN, OH, KK
|
||||
Valve ZP has flow rate=0; tunnels lead to valves EG, MC
|
||||
Valve AR has flow rate=0; tunnels lead to valves UU, OY
|
||||
Valve OZ has flow rate=10; tunnels lead to valves YD, XL, CS, AT, QR
|
||||
Valve GV has flow rate=0; tunnels lead to valves XC, OY
|
||||
Valve PE has flow rate=0; tunnels lead to valves WW, AA
|
||||
Valve ZE has flow rate=0; tunnels lead to valves AA, CR
|
||||
Valve XL has flow rate=0; tunnels lead to valves OZ, AA
|
||||
Valve YI has flow rate=15; tunnels lead to valves QX, MZ, EJ, DY, ZV
|
||||
Valve OQ has flow rate=0; tunnels lead to valves FX, VN
|
||||
Valve MG has flow rate=0; tunnels lead to valves TU, CS
|
||||
Valve LS has flow rate=0; tunnels lead to valves CR, ZV
|
||||
@@ -0,0 +1,10 @@
|
||||
Valve AA has flow rate=0; tunnels lead to valves DD, II, BB
|
||||
Valve BB has flow rate=13; tunnels lead to valves CC, AA
|
||||
Valve CC has flow rate=2; tunnels lead to valves DD, BB
|
||||
Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE
|
||||
Valve EE has flow rate=3; tunnels lead to valves FF, DD
|
||||
Valve FF has flow rate=0; tunnels lead to valves EE, GG
|
||||
Valve GG has flow rate=0; tunnels lead to valves FF, HH
|
||||
Valve HH has flow rate=22; tunnel leads to valve GG
|
||||
Valve II has flow rate=0; tunnels lead to valves AA, JJ
|
||||
Valve JJ has flow rate=21; tunnel leads to valve II
|
||||
@@ -0,0 +1,232 @@
|
||||
--- Day 16: Proboscidea Volcanium ---
|
||||
The sensors have led you to the origin of the distress signal: yet another handheld device, just like the one the Elves gave you. However, you don't see any Elves around; instead, the device is surrounded by elephants! They must have gotten lost in these tunnels, and one of the elephants apparently figured out how to turn on the distress signal.
|
||||
|
||||
The ground rumbles again, much stronger this time. What kind of cave is this, exactly? You scan the cave with your handheld device; it reports mostly igneous rock, some ash, pockets of pressurized gas, magma... this isn't just a cave, it's a volcano!
|
||||
|
||||
You need to get the elephants out of here, quickly. Your device estimates that you have 30 minutes before the volcano erupts, so you don't have time to go back out the way you came in.
|
||||
|
||||
You scan the cave for other options and discover a network of pipes and pressure-release valves. You aren't sure how such a system got into a volcano, but you don't have time to complain; your device produces a report (your puzzle input) of each valve's flow rate if it were opened (in pressure per minute) and the tunnels you could use to move between the valves.
|
||||
|
||||
There's even a valve in the room you and the elephants are currently standing in labeled AA. You estimate it will take you one minute to open a single valve and one minute to follow any tunnel from one valve to another. What is the most pressure you could release?
|
||||
|
||||
For example, suppose you had the following scan output:
|
||||
|
||||
Valve AA has flow rate=0; tunnels lead to valves DD, II, BB
|
||||
Valve BB has flow rate=13; tunnels lead to valves CC, AA
|
||||
Valve CC has flow rate=2; tunnels lead to valves DD, BB
|
||||
Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE
|
||||
Valve EE has flow rate=3; tunnels lead to valves FF, DD
|
||||
Valve FF has flow rate=0; tunnels lead to valves EE, GG
|
||||
Valve GG has flow rate=0; tunnels lead to valves FF, HH
|
||||
Valve HH has flow rate=22; tunnel leads to valve GG
|
||||
Valve II has flow rate=0; tunnels lead to valves AA, JJ
|
||||
Valve JJ has flow rate=21; tunnel leads to valve II
|
||||
All of the valves begin closed. You start at valve AA, but it must be damaged or jammed or something: its flow rate is 0, so there's no point in opening it. However, you could spend one minute moving to valve BB and another minute opening it; doing so would release pressure during the remaining 28 minutes at a flow rate of 13, a total eventual pressure release of 28 * 13 = 364. Then, you could spend your third minute moving to valve CC and your fourth minute opening it, providing an additional 26 minutes of eventual pressure release at a flow rate of 2, or 52 total pressure released by valve CC.
|
||||
|
||||
Making your way through the tunnels like this, you could probably open many or all of the valves by the time 30 minutes have elapsed. However, you need to release as much pressure as possible, so you'll need to be methodical. Instead, consider this approach:
|
||||
|
||||
== Minute 1 ==
|
||||
No valves are open.
|
||||
You move to valve DD.
|
||||
|
||||
== Minute 2 ==
|
||||
No valves are open.
|
||||
You open valve DD.
|
||||
|
||||
== Minute 3 ==
|
||||
Valve DD is open, releasing 20 pressure.
|
||||
You move to valve CC.
|
||||
|
||||
== Minute 4 ==
|
||||
Valve DD is open, releasing 20 pressure.
|
||||
You move to valve BB.
|
||||
|
||||
== Minute 5 ==
|
||||
Valve DD is open, releasing 20 pressure.
|
||||
You open valve BB.
|
||||
|
||||
== Minute 6 ==
|
||||
Valves BB and DD are open, releasing 33 pressure.
|
||||
You move to valve AA.
|
||||
|
||||
== Minute 7 ==
|
||||
Valves BB and DD are open, releasing 33 pressure.
|
||||
You move to valve II.
|
||||
|
||||
== Minute 8 ==
|
||||
Valves BB and DD are open, releasing 33 pressure.
|
||||
You move to valve JJ.
|
||||
|
||||
== Minute 9 ==
|
||||
Valves BB and DD are open, releasing 33 pressure.
|
||||
You open valve JJ.
|
||||
|
||||
== Minute 10 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve II.
|
||||
|
||||
== Minute 11 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve AA.
|
||||
|
||||
== Minute 12 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve DD.
|
||||
|
||||
== Minute 13 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve EE.
|
||||
|
||||
== Minute 14 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve FF.
|
||||
|
||||
== Minute 15 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve GG.
|
||||
|
||||
== Minute 16 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve HH.
|
||||
|
||||
== Minute 17 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You open valve HH.
|
||||
|
||||
== Minute 18 ==
|
||||
Valves BB, DD, HH, and JJ are open, releasing 76 pressure.
|
||||
You move to valve GG.
|
||||
|
||||
== Minute 19 ==
|
||||
Valves BB, DD, HH, and JJ are open, releasing 76 pressure.
|
||||
You move to valve FF.
|
||||
|
||||
== Minute 20 ==
|
||||
Valves BB, DD, HH, and JJ are open, releasing 76 pressure.
|
||||
You move to valve EE.
|
||||
|
||||
== Minute 21 ==
|
||||
Valves BB, DD, HH, and JJ are open, releasing 76 pressure.
|
||||
You open valve EE.
|
||||
|
||||
== Minute 22 ==
|
||||
Valves BB, DD, EE, HH, and JJ are open, releasing 79 pressure.
|
||||
You move to valve DD.
|
||||
|
||||
== Minute 23 ==
|
||||
Valves BB, DD, EE, HH, and JJ are open, releasing 79 pressure.
|
||||
You move to valve CC.
|
||||
|
||||
== Minute 24 ==
|
||||
Valves BB, DD, EE, HH, and JJ are open, releasing 79 pressure.
|
||||
You open valve CC.
|
||||
|
||||
== Minute 25 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
== Minute 26 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
== Minute 27 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
== Minute 28 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
== Minute 29 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
== Minute 30 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
This approach lets you release the most pressure possible in 30 minutes with this valve layout, 1651.
|
||||
|
||||
Work out the steps to release the most pressure in 30 minutes. What is the most pressure you can release?
|
||||
|
||||
Your puzzle answer was 2087.
|
||||
|
||||
The first half of this puzzle is complete! It provides one gold star: *
|
||||
|
||||
--- Part Two ---
|
||||
You're worried that even with an optimal approach, the pressure released won't be enough. What if you got one of the elephants to help you?
|
||||
|
||||
It would take you 4 minutes to teach an elephant how to open the right valves in the right order, leaving you with only 26 minutes to actually execute your plan. Would having two of you working together be better, even if it means having less time? (Assume that you teach the elephant before opening any valves yourself, giving you both the same full 26 minutes.)
|
||||
|
||||
In the example above, you could teach the elephant to help you as follows:
|
||||
|
||||
== Minute 1 ==
|
||||
No valves are open.
|
||||
You move to valve II.
|
||||
The elephant moves to valve DD.
|
||||
|
||||
== Minute 2 ==
|
||||
No valves are open.
|
||||
You move to valve JJ.
|
||||
The elephant opens valve DD.
|
||||
|
||||
== Minute 3 ==
|
||||
Valve DD is open, releasing 20 pressure.
|
||||
You open valve JJ.
|
||||
The elephant moves to valve EE.
|
||||
|
||||
== Minute 4 ==
|
||||
Valves DD and JJ are open, releasing 41 pressure.
|
||||
You move to valve II.
|
||||
The elephant moves to valve FF.
|
||||
|
||||
== Minute 5 ==
|
||||
Valves DD and JJ are open, releasing 41 pressure.
|
||||
You move to valve AA.
|
||||
The elephant moves to valve GG.
|
||||
|
||||
== Minute 6 ==
|
||||
Valves DD and JJ are open, releasing 41 pressure.
|
||||
You move to valve BB.
|
||||
The elephant moves to valve HH.
|
||||
|
||||
== Minute 7 ==
|
||||
Valves DD and JJ are open, releasing 41 pressure.
|
||||
You open valve BB.
|
||||
The elephant opens valve HH.
|
||||
|
||||
== Minute 8 ==
|
||||
Valves BB, DD, HH, and JJ are open, releasing 76 pressure.
|
||||
You move to valve CC.
|
||||
The elephant moves to valve GG.
|
||||
|
||||
== Minute 9 ==
|
||||
Valves BB, DD, HH, and JJ are open, releasing 76 pressure.
|
||||
You open valve CC.
|
||||
The elephant moves to valve FF.
|
||||
|
||||
== Minute 10 ==
|
||||
Valves BB, CC, DD, HH, and JJ are open, releasing 78 pressure.
|
||||
The elephant moves to valve EE.
|
||||
|
||||
== Minute 11 ==
|
||||
Valves BB, CC, DD, HH, and JJ are open, releasing 78 pressure.
|
||||
The elephant opens valve EE.
|
||||
|
||||
(At this point, all valves are open.)
|
||||
|
||||
== Minute 12 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
...
|
||||
|
||||
== Minute 20 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
...
|
||||
|
||||
== Minute 26 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
With the elephant helping, after 26 minutes, the best you could do would release a total of 1707 pressure.
|
||||
|
||||
With you and an elephant working together for 26 minutes, what is the most pressure you could release?
|
||||
|
||||
Answer:
|
||||
|
||||
|
||||
Although it hasn't changed, you can still get your puzzle input.
|
||||
|
||||
You can also [Share] this puzzle.
|
||||
Reference in New Issue
Block a user