diff --git a/AdventOfCode2022.vcxproj b/AdventOfCode2022.vcxproj index 5b339ee..cc76e90 100644 --- a/AdventOfCode2022.vcxproj +++ b/AdventOfCode2022.vcxproj @@ -133,6 +133,7 @@ + diff --git a/AdventOfCode2022.vcxproj.filters b/AdventOfCode2022.vcxproj.filters index 23df08e..fbd3a16 100644 --- a/AdventOfCode2022.vcxproj.filters +++ b/AdventOfCode2022.vcxproj.filters @@ -36,6 +36,9 @@ Source Files + + Source Files + diff --git a/input/day07 b/input/day07 index e69de29..bcbb513 100644 --- a/input/day07 +++ b/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 \ No newline at end of file diff --git a/src/days/day07.cpp b/src/days/day07.cpp index 9ca1440..6e17768 100644 --- a/src/days/day07.cpp +++ b/src/days/day07.cpp @@ -1,11 +1,69 @@ #include "../aoc2022.h" +enum ECommand { + eCD, + eLS, +}; +struct SFileStructure { + std::string name; + SFileStructure* parent; + std::vector children; +}; + +struct SDirectory : public SFileStructure{}; +struct SFile : public SFileStructure { + int fileSize; +}; + template struct SDay07 : public SDay { //Class constructor using SDay::SDay; + SFileStructure* root = new SFileStructure{"/", nullptr, std::vector}; + //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 }); + directory = directory->children.back(); + } + + void cd(SFileStructure* directory, const std::string& newDirectory) const { + directory->children.push_back(new SDirectory{ newDirectory, directory, std::vector }); + directory = directory->children.back(); + } };