Day 12 part 1 complete

master
sigonasr2 12 months ago
parent 38aaecd33d
commit 014608d263
  1. 140
      Day 12/Day 12.vcxproj
  2. 27
      Day 12/Day 12.vcxproj.filters
  3. 2
      Day 12/day12_1.txt
  4. 1000
      Day 12/day12_2.txt
  5. 172
      Day 12/main.cpp
  6. 6695
      Day 12/olcPixelGameEngine.h
  7. 10
      Project3.sln
  8. 2
      Project3/Project3.vcxproj

@ -0,0 +1,140 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{9a7eb0ab-d3c0-4e08-b788-fea6215485b1}</ProjectGuid>
<RootNamespace>Day_12</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="olcPixelGameEngine.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="olcPixelGameEngine.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

@ -0,0 +1,2 @@
...#?.?.?. 1,1
?...#?.?.?. 1,1

File diff suppressed because it is too large Load Diff

@ -0,0 +1,172 @@
#pragma region Hidden Setup Stuff
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
using namespace olc;
enum Run{
FILE1,
FILE2
};
// Override base class with your custom functionality
class AoC2023 : public olc::PixelGameEngine
{
std::vector<std::string>lines;
bool waitForRender=false;
void wait(int pauseMs=0){
waitForRender=true;
while(waitForRender);
std::this_thread::sleep_for(std::chrono::milliseconds(pauseMs));
}
#pragma endregion
const int DAY = 12;
Run runInput=FILE1;
std::vector<int>countGaps(std::string springList){
std::vector<int>sizes;
int hashRun=0;
for(char c:springList){
if(c=='#')hashRun++;
else{
if(hashRun>0)sizes.push_back(hashRun);
hashRun=0;
}
}
if(hashRun>0)sizes.push_back(hashRun);
return sizes;
}
size_t CalculateCombinations(std::string springList,std::vector<int>sizes){
long combinationCount=0;
size_t questionMarkCount=std::count(springList.begin(),springList.end(),'?');
size_t possibilities=std::pow(2,questionMarkCount);
for(size_t i=0;i<possibilities;i++){
std::string modifiedSpringList=springList;
size_t springIndex=0;
size_t questionMarkPos=-1;
while(springIndex!=questionMarkCount){
questionMarkPos=springList.find('?',questionMarkPos+1);
if(i&(1<<springIndex))modifiedSpringList[questionMarkPos]='#';
else modifiedSpringList[questionMarkPos]='.';
springIndex++;
}
std::vector<int>modifiedSizeList=countGaps(modifiedSpringList);
if(sizes.size()==modifiedSizeList.size()&&std::equal(sizes.begin(),sizes.end(),modifiedSizeList.begin())){
combinationCount++;
}
}
return combinationCount;
}
size_t CalculateCombinationsQuick(std::string springList,std::vector<int>sizes){
long long total=0;
size_t combinationCount=CalculateCombinations(springList,sizes);
size_t combinationCount2=springList[springList.size()-1]=='#'?combinationCount:CalculateCombinations("?"+springList,sizes);
size_t combinationCount3=CalculateCombinations(springList+"?",sizes);
total+=combinationCount;
for(int i=0;i<4;i++){
total*=std::max(combinationCount2,combinationCount3);
}
return total;
}
void doStuff(){
long long sum=0;
std::vector<std::pair<std::string,std::vector<int>>>springLists;
while(true){ //lines is accessible as a global.
for(std::string&line:lines){
std::string springList=line.substr(0,line.find(' '));
std::vector<int>sizes;
std::string sizeList=line.substr(line.find(' ')+1);
size_t comma=sizeList.find(',');
while(sizeList.length()>0){
int numb=std::stoi(sizeList.substr(0,comma));
sizes.push_back(numb);
if(comma==std::string::npos)break;
sizeList=sizeList.substr(comma+1);
comma=sizeList.find(',');
}
springLists.push_back({springList,sizes});
}
std::sort(springLists.begin(),springLists.end(),[](std::pair<std::string,std::vector<int>>&spring1,std::pair<std::string,std::vector<int>>&spring2){
return std::count(spring1.first.begin(),spring1.first.end(),'?')<std::count(spring2.first.begin(),spring2.first.end(),'?');
});
for(auto&spring:springLists){
std::string modifiedSpringList=spring.first;
std::vector<int>modifiedSizes=spring.second;
for(int i=0;i<4;i++){
modifiedSpringList+="?"+spring.first;
std::copy(spring.second.begin(),spring.second.end(),std::back_inserter(modifiedSizes));
}
//long long bruteForceTotal=CalculateCombinations(modifiedSpringList,modifiedSizes);
long long total=CalculateCombinations(spring.first,spring.second);
//std::cout<<bruteForceTotal<<" vs "<<total<<": "<<spring.first<<std::endl;
//if(bruteForceTotal!=total)throw;
std::cout<<total<<std::endl;
}
std::cout<<sum<<std::endl;
break;
//wait(0); //Wait for 0ms and render the screen (calls draw())
}
}
void draw(){ //Only use Sprites! If using decals, you must reference global variables!
Clear(BLACK);
int count=0;
for(std::string&line:lines){
DrawString({0,count*32},line,WHITE,4);
count++;
}
}
#pragma region Hidden Engine Stuff
public:
AoC2023()
{
// Name your application
std::string fileName="day"+std::to_string(DAY)+"_1.txt";
if(runInput==FILE2){fileName="day"+std::to_string(DAY)+"_2.txt";}
std::ifstream file(fileName);
while(file.good()){
std::string line;
std::getline(file,line);
lines.push_back(line);
}
sAppName = "Advent of Code 2023 - Day "+std::to_string(DAY);
}
public:
bool OnUserCreate() override
{
return true;
}
bool OnUserUpdate(float fElapsedTime) override
{
static std::thread aocSolver(&AoC2023::doStuff,this);
if(waitForRender){
draw();
waitForRender=false;
}
return true;
}
};
int main()
{
AoC2023 game;
if (game.Construct(640, 480, 2,2))
game.Start();
return 0;
}
#pragma endregion

File diff suppressed because it is too large Load Diff

@ -27,6 +27,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Day 10", "Day 10\Day 10.vcx
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Day 11", "Day 11\Day 11.vcxproj", "{520A82A0-BD04-44D6-B361-07F095A5ABA0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Day 12", "Day 12\Day 12.vcxproj", "{9A7EB0AB-D3C0-4E08-B788-FEA6215485B1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@ -131,6 +133,14 @@ Global
{520A82A0-BD04-44D6-B361-07F095A5ABA0}.Release|x64.Build.0 = Release|x64
{520A82A0-BD04-44D6-B361-07F095A5ABA0}.Release|x86.ActiveCfg = Release|Win32
{520A82A0-BD04-44D6-B361-07F095A5ABA0}.Release|x86.Build.0 = Release|Win32
{9A7EB0AB-D3C0-4E08-B788-FEA6215485B1}.Debug|x64.ActiveCfg = Debug|x64
{9A7EB0AB-D3C0-4E08-B788-FEA6215485B1}.Debug|x64.Build.0 = Debug|x64
{9A7EB0AB-D3C0-4E08-B788-FEA6215485B1}.Debug|x86.ActiveCfg = Debug|Win32
{9A7EB0AB-D3C0-4E08-B788-FEA6215485B1}.Debug|x86.Build.0 = Debug|Win32
{9A7EB0AB-D3C0-4E08-B788-FEA6215485B1}.Release|x64.ActiveCfg = Release|x64
{9A7EB0AB-D3C0-4E08-B788-FEA6215485B1}.Release|x64.Build.0 = Release|x64
{9A7EB0AB-D3C0-4E08-B788-FEA6215485B1}.Release|x86.ActiveCfg = Release|Win32
{9A7EB0AB-D3C0-4E08-B788-FEA6215485B1}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -91,6 +91,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -119,6 +120,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

Loading…
Cancel
Save