Part 1 done

master
sigonasr2 12 months ago
parent ce1cda06b4
commit 7e8c273c5d
  1. 138
      Day 3/Day 3.vcxproj
  2. 27
      Day 3/Day 3.vcxproj.filters
  3. 10
      Day 3/Day3_1.txt
  4. 140
      Day 3/Day3_2.txt
  5. 241
      Day 3/main.cpp
  6. 6695
      Day 3/olcPixelGameEngine.h
  7. 10
      Project3.sln

@ -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>{cf11a7b9-18f3-4cac-b861-f6faf8b4a4b9}</ProjectGuid>
<RootNamespace>Day_3</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,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,10 @@
467..114..
...*......
..35..633.
......#...
617*......
.....+.58.
..592.....
......755.
...$.*....
.664.598..

@ -0,0 +1,140 @@
............677..........................................................................227.....730..35.......318...........92...166.......
....%..863..#......................36.............956..337%......692..............*744....$..........*......../.....187..-..................
..346...*.....475.440....903&..996*...404+.395...*..............*.......&253.223.....................453..535......@....265.....290$........
.........470.*.....+..........................*.........148...40....361...................883.............*....%............649.............
.............587..........#..........848*.............../.........................................415....445....947............*...509......
......170..............922..79*660.......87...802...........................669.152...867...........*.........................926....+.53...
.......-..#319..915................846......../......120...870*874..610.........$....-.......577.....825.....430$.....689...................
......................700.........*................................*..................../.........................693.*....734&......@.59...
..........247..........*.......444....768....569.248..430..565.....82............525...794...171...................*..160........39.25.*....
..........*.........560............56*......$..........&...*............70-........&.........*....397....571.....297.............*.....422..
......338..481........../..#220...............116.........194..................#.....=....-..529..=........................../....381.......
.892....*....../...708.856.......405.............*324................&...922....60..288..810.........747............*876./....180...........
....*..41......456........................652..................48..110..+.....................199.....*..........824......471........261....
..317......+1........29...316&...368&............%.365...212....*..............................*..292..70..............................*....
.......................................*......616..-.....*....596........*699.978*259....309..660....*...........90....634.....631......987.
140........2*....285...836&..........13.8.............264.............945...............*............323....514.&.........-......%..........
......&......634..*..........816...........................41..=..............@670......648................+.............................926
......343.........221....157....*.......=..492.319..............659......238.........................-.......113.......187...863............
........................*......937....471........*...274..................*....../244......22..332...908.......*..........#..*..............
.......610.............670.693..................182...*..618.............865................................678........85.....948...........
.........*...334.............../.....21*853.........491..../...524...............494........794.....401.........$........*327...............
........270.../................164.......................#....=..............235...*....-..*.......*.............142..............738*......
...579.............@...823...............596........+263.797.....916..............632..618..335.996......504*..................+......853...
....&...646*.872...805....*...-788.......*.........................*.......985*..............................440.......310..826.....+.......
..............*.........54..........104...238.........787...........79.........449.674........204......................*...........808......
...949....396..................664....$.........626..*...............................*.......*....923..30....482........111.............+...
...$......*...................../.............*......387.........333...-........@.750.......737.........*.....*.............890..707.....852
.........264....247.....416+..................177...........55..........251..911.........................88...741.................@.........
................*..............-........................232..*.....737...............597..............................=.+...............24..
.................456............109..907................../...656.......................*..................855.451.958..783.........854*....
.....65*....#188.......894............................@.....&................380.302.133..507.................*..............227............
..71....14..................774..%109..821...182*......85...256......314.......%..........-....148..$.824*591......653........*......&435...
.........................$./.............@...........................=............228..............32.........*........%989..121............
.......................64.......545.........*458......735....435...........869.......+...........=.........307.......................*......
74...209../885..................*....&368.86.........*..........*....965.....................919..226................990..........381.566...
........#..........970.150....910.=..............973.502....$.603..#..*....429..557...#................665.......307........................
...-.........486..........=.......514.............*......621......59.654......*...*....756...584.....%....*453...*....250...328...995.......
....997.........*.......................316......533........................100..485.........*.......955........792..........*.......*......
.........420....111..........273.430.......*889..........824..338..91.55.............656....70...............................936...713......
......#....*........647......*...../.484.......................*..*......#376..........................425.613..............................
...568....151....$.......95.............*...66.....818..453.735..817.319......568*764...........242.....+.............829.1.................
..............216....345......................*.....*.................*...549............251.......*.........*44.......*...*352......597*7..
.....138..240......$...*.............34..197.988.....760..981....*....682....*...263/...*.........19......678.......$..839.......70.........
........*...*....270.........147.700.......*...............+..470.849.......625.........218..$.....................936..........*....@......
.......953..856.................*.........910........504.........................&..........830........874..................514.772..698....
814...................460...........................$............&49......804..394......................*...............747...*.............
........876...........@...............607......15........8...................$.........706..............767...972.......*...912....%........
.............805...83..............*......156..............924...719...............514*...........................936...........960..364....
...692........*....#......220...667.645....*........................=...977..628........415...................@....*..386....#.........*....
.............................$.............891.948..479...................-...*..........*...*385......*...173....113./...765..779......643.
..........$754......8............599...........*............373.............814....537.307..........552.........................*...........
......................*111..874..&...887....820.........73..*..........196.....................260.......%......915.774.........../.........
..........670*484.624..........$.......................%.....17........*.......91@..703*705...............298......*............160.........
.....256...............&..................833.....@......319....&310.778........................214...................195..............7....
......*......-.......229.................*........23.........82.............604..428.....258&..*.................303..*......198............
....554...262...621*...........959....475..28............836.*...11*68...........#............602..73.....+471..*....161.61.*...........652.
...............................*..........................$..324.........&.........-.....950........*..........921.......*...551...799$.$...
..............=306..19/.397*....127.......*..........794..........461....997........429.#.........923.......................................
..950.....225...............667........743.560.........*....678....*..................................240.............*.....................
...........*......................&727..................229...*...20............508@...464........312.....399..945...430....................
............239......*453.....................................908.........339.........*........................*............394@............
.606..647......................544.....*765.............908/...............*....318...393................481.445..................714.......
...*.../......859......362....../...352...........736.........970.......138....................%....850............529........#......*561...
..841.............*.......$................225...=....*470..................280....109......441........*785....281*........576..@929........
...........146..34.965......272...............*....418......-....=918..862.*......*...................................#365..................
.821*388......*.....................781......778...........839...........*..779.........635..#....243..+............*.............*493...147
...............991....463...211*......$...........291...............+.............970...*....153..*....81..........614...720....63..........
...........714..................127......81......&.................307.............-.....948.....565......907...........*...................
...........................-..............#...#...........................&..........145.....................*365..590..711....830....511...
..........136..-...810....9....................178...........*440....696...792..............260........18......................*............
......364....*.193...+..........5*.....390+..........580..630...........*..............324./....463....*........................846......915
.........*..............868.......593.......384......../....................201........*..............343..852......96......................
......303..64.............................................493.........694............833....758........................266......531.........
.............*823..................................461............295..........100$.......%...=.884..433....929.......&.........$...........
521..........................&.................120.........................../..........996.....*.......&....*...971.................-......
.......@..227...............440..308.../................152.......#.........82.660.%265......599.............646..*...505....547$.....983...
.....157................................22.......=.......%...&.....12....................................428.....641........................
...........398.....381.../...248................492........631.....................128...../...577.......$............792...................
..........+...............28.........41.....386......15............*937......660...*....915.......*.594.................$.......964.........
..............216.............351&...*........*.....*........$..449...............328..........270...#.........900.........930.*.....941....
..552.224.402*......895.............302.462....248...374...142................535..........................884....%..71....$...997...*...589
.....*.....................270...-........=.-..........................760..........151..508..........21.....*......+.......................
........341..%898.......$......612...........103..............895....*.*.........@.....-.....99........*..939.....*.........................
........*............295.............591.................458.+.....374..70........284................283.........340..89......820......932..
......284.......826........+838........*........*.........$...................................89........................&.....=.......*.....
..........818..........................741...175.495................489.........................*.........469..565..%...........613.32......
788.982...*.........468..............................952....73...............588...336........+...498*805....*...*...332.........*..........
....../.884...%.127....&..980...#.........214...............+.................*....*.......336...............812..43.......475..908.........
............294..............-.681......=......1........647.............180..895..760....%................91...............*.........674....
...24..#.................739.............657..=....149.....*..296.737..*..............553...............*...*473........474...%.............
.......694.......*..%....*.........*..................-.117....*.....*..............................953.793....................653.....635..
..............519....963..640......718......................*...693.83.............................$.................................-..#...
.......................................463...........*39..867...........200..................766.........893........262.89.777-.....476.....
......................@790........................983...................*.....................*.............*906...../..*.........%.........
.../.......417..619...................................................944...973.....#......664.........203...............504.824...626.149..
...316...............847...........%....................382...1................*.825..223.............@.........+............*.........*....
...............816....*.....744..771.628..............*....*..*..............433......*..........................303......569..725......221.
.....&543........*.774.......*.....................461..357..131...583..892$.........627...978..630...#653........................#.........
352............540............509.504*......109......................*.......................+.-...............431..486..250....%...........
...+.......774.....343........................*.......&............859.....499......................./................*......448....425.....
..............*857.$........26....+.....$..705..491.128......871............#..659....................119.....%80.770.25....................
......66....................*..453....497.........-.......*.....*................@.....833..........................................-.......
.....*........196........535........................./.233.230.238.....................*...#.56*...........757.......620..........$..694....
...226.122....*.....116...............78$.........652.....................+589......260..633....97....153...............*..$...142.......464
........@......493..........883...862.................199......................100......................%.............445...25.....*........
...........372.........388...*...%.......13*506......%...../855...-456.........+................373........@....976.............243.965.....
.....234..*........200...&.659...........................-...............353......451..........*..........997....*..........................
........*..........*...........205..................#...346.................@....-.......890..455.....819.....673..733*473..................
..........970...132...$....509*..........#.......437..........290..../489...........59.................*........................961.........
..972.192.@.........152.@.......$...876...993.............449....&.............335.*.....184.........723.......................+.......+....
...............899......470.82..908..............10.......+...........375......#....635...*................*538.....$..228..%...........587.
...751........................-......................996....351........*..422...........246.......#393..168.......576...*...652...784.......
....................997.................49.............*...*....118......*.....998..$..........2............#....................*..........
.........-749..612..*.............140..$.......659.....750..965....*...187.....*...973..............859..908......951.....104.....749...+...
.302...............257...........................*...............851...........444..........58*119...*........162....@......*............431
....*........260*........324................262...147.......+..............245........................604.47...............333..../.........
.................926........*248...............*..........660................*......438=..250.................622................103....543.
............@223............................933.........................605..285............*..................*.....622...............#....
....&...873.............6..530.......251.........17..529...................*.................945...905.........505...*.....181..............
.....60....*........94..&...&..........#........+....../....746*768........849.......985*445.............*...........201..$....307...-......
..........838.365..$.............595+..............-............................256..............533......84..................%.......564...
.....855........*.....%...............854.........20..739..........+............................................992.........................
.981..*..........75..147.390..................842....../..997......145.......593..............#...........769../........88..............323.
...*..911.................*..997.........................*................15*.......642....327........148*................*268..........@...
..127.........................@...........856........284.753..469.....+.......611=.....&.........................63....&........@346........
......758..............670...............*.....431..............*.460..988..=...................................*.....538..............#697.
.........................*.......311.=37.........*............524...*.......315..316..902.....864*.....%529.....392.......859..156@.........
.....$..............610......478.#..............335................337.................-..........828........................#......530.191.
.892.914......................%..........................283....................208........626.........&.40.....443..626.$.............*....
...*.....................963....645*........694*.................539.....317..................%......555............*.....450......+........
..412..422..373%...713$..%......................778.159.........*...........#.......978...................+......647..........$..885....&...
...............................58...........383.....%..........185...376...........+.....158.........%.....398.............203.........784..
......360...914*875.104&........&.673....-.....*.*....................*...................*.....590.417.60.......................*..........
.......*.................................386.592..445...............74...........&........864.............$.370.....75........125.102...292.
........950.522..422&.204%......918.........................228................918............../..............-...*...951..................
.....@.........*..................................................228..840$.....................584......72..#....563...$..717..113.........
..250...........817.........#........614...224...164...506......................362....873...........568*....920...............*............
......159.................553..294#...*.........*......................42..$...........*......884.......................950...482..611...249
........*....978*275.................974...*....81.........../...........%.405.........224.....-....*......409*20....../............*...*...
.122.273...............759....137...........574............229...................................497.41............................872.78...

@ -0,0 +1,241 @@
#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 = 3;
Run runInput=FILE1;
struct numb{
vi2d pos;
int number;
};
std::vector<numb>parts;
std::vector<std::vector<char>>board;
void doStuff2(){
while(true){ //lines is accessible as a global.
int sum=0;
vi2d pos={};
for(std::string&line:lines){
std::string numb="";
bool isAdjacent=false;
std::vector<char>row;
vi2d initialNumberPos={};
for(int i=0;i<line.size();i++){
if(line[i]>='0'&&line[i]<='9'){
if(numb.length()==0){
initialNumberPos=pos;
}
numb+=line[i];
}else
if(numb.length()>0){
//A number has been parsed.
parts.push_back({initialNumberPos,atoi(numb.c_str())});
numb="";
}
row.push_back(line[i]);
pos.x++;
}
if(numb.length()>0){
//A number has been parsed.
parts.push_back({initialNumberPos,atoi(numb.c_str())});
}
board.push_back(row);
pos.y++;
pos.x=0;
std::cout<<line<<std::endl;
}
for(numb&number:parts){
int myNumb=number.number;
vi2d startingPos=number.pos;
while(myNumb>0){
auto validatePos=[&](vi2d checkPos){
return startingPos.y+checkPos.y>0&&startingPos.y+checkPos.y<board.size()-1&&
startingPos.x+checkPos.x>0&&startingPos.x+checkPos.x<board[startingPos.y+checkPos.y].size()-1;
};
auto testChar=[&](char test){
if(test!='.'&&!(test>='0'&&test<='9')){
sum+=number.number;
std::cout<<number.number<<" was adjacent to a symbol"<<std::endl;
return true;
}
return false;
};
vi2d checkPos={1,0};
if(validatePos({1,0})){if(testChar(board[startingPos.y][startingPos.x+1]))break;}
if(validatePos({0,1})){if(testChar(board[startingPos.y+1][startingPos.x]))break;}
if(validatePos({-1,0})){if(testChar(board[startingPos.y][startingPos.x-1]))break;}
if(validatePos({0,-1})){if(testChar(board[startingPos.y-1][startingPos.x]))break;}
if(validatePos({1,1})){if(testChar(board[startingPos.y+1][startingPos.x+1]))break;}
if(validatePos({1,-1})){if(testChar(board[startingPos.y-1][startingPos.x+1]))break;}
if(validatePos({-1,1})){if(testChar(board[startingPos.y+1][startingPos.x-1]))break;}
if(validatePos({-1,-1})){if(testChar(board[startingPos.y-1][startingPos.x-1]))break;}
myNumb/=10;
startingPos.x++;
}
}
std::cout<<sum<<std::endl;
wait(0); //Wait for 0ms and render the screen (calls draw())
break;
}
}
void doStuff(){
while(true){ //lines is accessible as a global.
int sum=0;
vi2d pos={};
for(std::string&line:lines){
std::string numb="";
bool isAdjacent=false;
std::vector<char>row;
vi2d initialNumberPos={};
for(int i=0;i<line.size();i++){
if(line[i]>='0'&&line[i]<='9'){
if(numb.length()==0){
initialNumberPos=pos;
}
numb+=line[i];
}else
if(numb.length()>0){
//A number has been parsed.
parts.push_back({initialNumberPos,atoi(numb.c_str())});
numb="";
}
row.push_back(line[i]);
pos.x++;
}
if(numb.length()>0){
//A number has been parsed.
parts.push_back({initialNumberPos,atoi(numb.c_str())});
}
board.push_back(row);
pos.y++;
pos.x=0;
std::cout<<line<<std::endl;
}
for(numb&number:parts){
int myNumb=number.number;
vi2d startingPos=number.pos;
while(myNumb>0){
auto validatePos=[&](vi2d checkPos){
return startingPos.y+checkPos.y>0&&startingPos.y+checkPos.y<board.size()-1&&
startingPos.x+checkPos.x>0&&startingPos.x+checkPos.x<board[startingPos.y+checkPos.y].size()-1;
};
auto testChar=[&](char test){
if(test!='.'&&!(test>='0'&&test<='9')){
sum+=number.number;
std::cout<<number.number<<" was adjacent to a symbol"<<std::endl;
return true;
}
return false;
};
vi2d checkPos={1,0};
if(validatePos({1,0})){if(testChar(board[startingPos.y][startingPos.x+1]))break;}
if(validatePos({0,1})){if(testChar(board[startingPos.y+1][startingPos.x]))break;}
if(validatePos({-1,0})){if(testChar(board[startingPos.y][startingPos.x-1]))break;}
if(validatePos({0,-1})){if(testChar(board[startingPos.y-1][startingPos.x]))break;}
if(validatePos({1,1})){if(testChar(board[startingPos.y+1][startingPos.x+1]))break;}
if(validatePos({1,-1})){if(testChar(board[startingPos.y-1][startingPos.x+1]))break;}
if(validatePos({-1,1})){if(testChar(board[startingPos.y+1][startingPos.x-1]))break;}
if(validatePos({-1,-1})){if(testChar(board[startingPos.y-1][startingPos.x-1]))break;}
myNumb/=10;
startingPos.x++;
}
}
std::cout<<sum<<std::endl;
wait(0); //Wait for 0ms and render the screen (calls draw())
break;
}
}
void draw(){ //Only use Sprites! If using decals, you must reference global variables!
Clear(BLACK);
int count=0;
vi2d pos;
for(std::vector<char>&row:board){
for(char c:row){
DrawString(pos,std::string(1,c));
pos.x+=8;
}
pos.y+=8;
pos.x=0;
}
for(numb&number:parts){
std::string numbStr="";
int numb=number.number;
while(numb>0){
numbStr=std::to_string(numb%10)+numbStr;
numb/=10;
}
DrawString(number.pos*8,numbStr,RED);
}
}
#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::doStuff2,this);
if(waitForRender){
draw();
waitForRender=false;
}
return true;
}
};
int main()
{
AoC2023 game;
if (game.Construct(1280, 960, 2, 2))
game.Start();
return 0;
}
#pragma endregion

File diff suppressed because it is too large Load Diff

@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Day 1", "Day 1\Day 1.vcxpro
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Day 2", "Day 2\Day 2.vcxproj", "{FC99E3F2-B7D0-44F4-8F65-E390976AC73B}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Day 2", "Day 2\Day 2.vcxproj", "{FC99E3F2-B7D0-44F4-8F65-E390976AC73B}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Day 3", "Day 3\Day 3.vcxproj", "{CF11A7B9-18F3-4CAC-B861-F6FAF8B4A4B9}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64
@ -41,6 +43,14 @@ Global
{FC99E3F2-B7D0-44F4-8F65-E390976AC73B}.Release|x64.Build.0 = Release|x64 {FC99E3F2-B7D0-44F4-8F65-E390976AC73B}.Release|x64.Build.0 = Release|x64
{FC99E3F2-B7D0-44F4-8F65-E390976AC73B}.Release|x86.ActiveCfg = Release|Win32 {FC99E3F2-B7D0-44F4-8F65-E390976AC73B}.Release|x86.ActiveCfg = Release|Win32
{FC99E3F2-B7D0-44F4-8F65-E390976AC73B}.Release|x86.Build.0 = Release|Win32 {FC99E3F2-B7D0-44F4-8F65-E390976AC73B}.Release|x86.Build.0 = Release|Win32
{CF11A7B9-18F3-4CAC-B861-F6FAF8B4A4B9}.Debug|x64.ActiveCfg = Debug|x64
{CF11A7B9-18F3-4CAC-B861-F6FAF8B4A4B9}.Debug|x64.Build.0 = Debug|x64
{CF11A7B9-18F3-4CAC-B861-F6FAF8B4A4B9}.Debug|x86.ActiveCfg = Debug|Win32
{CF11A7B9-18F3-4CAC-B861-F6FAF8B4A4B9}.Debug|x86.Build.0 = Debug|Win32
{CF11A7B9-18F3-4CAC-B861-F6FAF8B4A4B9}.Release|x64.ActiveCfg = Release|x64
{CF11A7B9-18F3-4CAC-B861-F6FAF8B4A4B9}.Release|x64.Build.0 = Release|x64
{CF11A7B9-18F3-4CAC-B861-F6FAF8B4A4B9}.Release|x86.ActiveCfg = Release|Win32
{CF11A7B9-18F3-4CAC-B861-F6FAF8B4A4B9}.Release|x86.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save