parent
3c207d50eb
commit
a4336e884c
@ -0,0 +1,138 @@ |
||||
<?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>{605f77bc-3c33-45b8-94c3-932481a79a75}</ProjectGuid> |
||||
<RootNamespace>Day_6</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> |
||||
</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> |
||||
</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,2 @@ |
||||
Time: 7 15 30 |
||||
Distance: 9 40 200 |
@ -0,0 +1,2 @@ |
||||
Time: 51 69 98 78 |
||||
Distance: 377 1171 1224 1505 |
@ -0,0 +1,151 @@ |
||||
#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 = 6; |
||||
Run runInput=FILE1; |
||||
|
||||
std::vector<int>time; |
||||
std::vector<int>distance; |
||||
|
||||
void doStuff(){ |
||||
while(true){ //lines is accessible as a global.
|
||||
bool firstLine=true; |
||||
for(std::string&line:lines){ |
||||
if(firstLine){//Time line.
|
||||
std::string data=line.substr(5); |
||||
std::string numb=""; |
||||
while(data.length()>0){ |
||||
if(data[0]>='0'&&data[0]<='9'){ |
||||
numb+=data[0]; |
||||
}else |
||||
if(numb.length()>0){ |
||||
time.push_back(std::stoi(numb)); |
||||
numb=""; |
||||
} |
||||
data=data.substr(1); |
||||
} |
||||
if(numb.length()>0){ |
||||
time.push_back(std::stoi(numb)); |
||||
numb=""; |
||||
} |
||||
firstLine=false; |
||||
}else{//Distance line.
|
||||
std::string data=line.substr(9); |
||||
std::string numb=""; |
||||
while(data.length()>0){ |
||||
if(data[0]>='0'&&data[0]<='9'){ |
||||
numb+=data[0]; |
||||
}else |
||||
if(numb.length()>0){ |
||||
distance.push_back(std::stoi(numb)); |
||||
numb=""; |
||||
} |
||||
data=data.substr(1); |
||||
} |
||||
if(numb.length()>0){ |
||||
distance.push_back(std::stoi(numb)); |
||||
numb=""; |
||||
} |
||||
} |
||||
} |
||||
long sum=0; |
||||
for(int i=0;i<time.size();i++){ |
||||
int targetTime=time[i]; |
||||
int targetDist=distance[i]; |
||||
int wins=0; |
||||
for(int holdTime=0;holdTime<=targetTime;holdTime++){ |
||||
int timeRemaining=targetTime-holdTime; |
||||
int speed=holdTime; |
||||
int distanceTraveled=speed*timeRemaining; |
||||
if(distanceTraveled>targetDist){ |
||||
wins++; |
||||
} |
||||
} |
||||
if(sum==0){ |
||||
sum=wins; |
||||
}else{ |
||||
sum*=wins; |
||||
} |
||||
} |
||||
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
Loading…
Reference in new issue