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:
@@ -1,11 +1,69 @@
|
||||
#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>
|
||||
struct SDay07 : public SDay<Output> {
|
||||
//Class constructor
|
||||
using SDay<Output>::SDay;
|
||||
|
||||
SFileStructure* root = new SFileStructure{"/", nullptr, std::vector<SFileStructure*>};
|
||||
|
||||
//Solutions to both days
|
||||
Output part1() 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();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user