Attempted Day7 - Way too tired to even fathom completing this. May get to take a look at it on another day
This commit is contained in:
parent
e56b0cdc9a
commit
9a68765006
@ -133,6 +133,7 @@
|
|||||||
<ClCompile Include="src\days\day04.cpp" />
|
<ClCompile Include="src\days\day04.cpp" />
|
||||||
<ClCompile Include="src\days\day05.cpp" />
|
<ClCompile Include="src\days\day05.cpp" />
|
||||||
<ClCompile Include="src\days\day06.cpp" />
|
<ClCompile Include="src\days\day06.cpp" />
|
||||||
|
<ClCompile Include="src\days\day07.cpp" />
|
||||||
<ClCompile Include="src\main.cpp" />
|
<ClCompile Include="src\main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -36,6 +36,9 @@
|
|||||||
<ClCompile Include="src\days\day06.cpp">
|
<ClCompile Include="src\days\day06.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\days\day07.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="src\aoc2022.h">
|
<ClInclude Include="src\aoc2022.h">
|
||||||
|
23
input/day07
23
input/day07
@ -0,0 +1,23 @@
|
|||||||
|
$ cd /
|
||||||
|
$ ls
|
||||||
|
dir a
|
||||||
|
14848514 b.txt
|
||||||
|
8504156 c.dat
|
||||||
|
dir d
|
||||||
|
$ cd a
|
||||||
|
$ ls
|
||||||
|
dir e
|
||||||
|
29116 f
|
||||||
|
2557 g
|
||||||
|
62596 h.lst
|
||||||
|
$ cd e
|
||||||
|
$ ls
|
||||||
|
584 i
|
||||||
|
$ cd ..
|
||||||
|
$ cd ..
|
||||||
|
$ cd d
|
||||||
|
$ ls
|
||||||
|
4060174 j
|
||||||
|
8033020 d.log
|
||||||
|
5626152 d.ext
|
||||||
|
7214296 k
|
@ -1,11 +1,69 @@
|
|||||||
#include "../aoc2022.h"
|
#include "../aoc2022.h"
|
||||||
|
|
||||||
|
enum ECommand {
|
||||||
|
eCD,
|
||||||
|
eLS,
|
||||||
|
};
|
||||||
|
struct SFileStructure {
|
||||||
|
std::string name;
|
||||||
|
SFileStructure* parent;
|
||||||
|
std::vector<SFileStructure*> children;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SDirectory : public SFileStructure{};
|
||||||
|
struct SFile : public SFileStructure {
|
||||||
|
int fileSize;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename Output>
|
template <typename Output>
|
||||||
struct SDay07 : public SDay<Output> {
|
struct SDay07 : public SDay<Output> {
|
||||||
//Class constructor
|
//Class constructor
|
||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
|
SFileStructure* root = new SFileStructure{"/", nullptr, std::vector<SFileStructure*>};
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
|
|
||||||
|
void parseInput() {
|
||||||
|
std::stringstream stream;
|
||||||
|
std::string line{ "" };
|
||||||
|
std::string instruction{ "" };
|
||||||
|
SFileStructure** current = root;
|
||||||
|
|
||||||
|
while (std::getline(this->input, line)) {
|
||||||
|
stream.clear();
|
||||||
|
stream.str(line);
|
||||||
|
stream >> instruction;
|
||||||
|
|
||||||
|
//Process a command
|
||||||
|
if (instruction == "$")
|
||||||
|
processCommand(stream, ¤t);
|
||||||
|
//Fill a directory
|
||||||
|
processDirectory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SFileStructure** processCommand(std::stringstream& command, SFileStructure* directory) const {
|
||||||
|
std::string opcode, operand;
|
||||||
|
command >> opcode;
|
||||||
|
command >> operand;
|
||||||
|
|
||||||
|
if (opcode == "cd")
|
||||||
|
cd(directory, operand);
|
||||||
|
|
||||||
|
return &directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
SFileStructure** processDirectory(std::stringstream& directoryElement, SFileStructure* directory) const {
|
||||||
|
std::string fileSize
|
||||||
|
directory->children.push_back(new SFile{ newDirectory, directory, std::vector<SFileStructure*> });
|
||||||
|
directory = directory->children.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cd(SFileStructure* directory, const std::string& newDirectory) const {
|
||||||
|
directory->children.push_back(new SDirectory{ newDirectory, directory, std::vector<SFileStructure*> });
|
||||||
|
directory = directory->children.back();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user