Day 7 aoc in progress
This commit is contained in:
1004
advent_of_code/2022/7/input.txt
Normal file
1004
advent_of_code/2022/7/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
99
advent_of_code/2022/7/main.cpp
Normal file
99
advent_of_code/2022/7/main.cpp
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
struct File;
|
||||||
|
|
||||||
|
class Directory{
|
||||||
|
public:
|
||||||
|
Directory* parent;
|
||||||
|
string name;
|
||||||
|
vector<Directory*> subdirectories;
|
||||||
|
vector<File*> files;
|
||||||
|
long container_size;
|
||||||
|
|
||||||
|
Directory (Directory* parent, string name) : parent(parent), name(name){
|
||||||
|
subdirectories.clear();
|
||||||
|
files.clear();
|
||||||
|
container_size = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct File{
|
||||||
|
string name;
|
||||||
|
long size;
|
||||||
|
Directory* parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
using ChangeDirectory = string;
|
||||||
|
using List = vector<string>;
|
||||||
|
using Command = variant<ChangeDirectory, List>;
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
ifstream input_file("test.txt");
|
||||||
|
string line;
|
||||||
|
|
||||||
|
vector<Command> commands;
|
||||||
|
List current_list;
|
||||||
|
bool reading_list = false;
|
||||||
|
|
||||||
|
// Parsing the input so it is nicer to handle later on
|
||||||
|
while(getline(input_file, line)){
|
||||||
|
if(line[0] == '$'){
|
||||||
|
if(reading_list){
|
||||||
|
commands.push_back(current_list);
|
||||||
|
current_list.clear();
|
||||||
|
reading_list = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
stringstream ss(line);
|
||||||
|
string _, comm;
|
||||||
|
ss >> _ >> comm;
|
||||||
|
|
||||||
|
if(comm == "cd"){
|
||||||
|
ChangeDirectory dir;
|
||||||
|
ss >> dir;
|
||||||
|
commands.push_back(dir);
|
||||||
|
} else{
|
||||||
|
reading_list = true;
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
current_list.push_back(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(reading_list){
|
||||||
|
commands.push_back(current_list);
|
||||||
|
reading_list = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setting up initial, empty directory
|
||||||
|
Directory
|
||||||
|
|
||||||
|
// Mapping out the file directory from all the commands
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for(auto c : commands){
|
||||||
|
if(c.index() == 0){
|
||||||
|
|
||||||
|
} else{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Printing parsed commands
|
||||||
|
|
||||||
|
// for(auto c : commands){
|
||||||
|
// if(c.index() == 0){
|
||||||
|
// cout << "$ cd " << get<0>(c) << '\n';
|
||||||
|
// } else{
|
||||||
|
// cout << "$ ls\n";
|
||||||
|
// for(auto s : get<1>(c)){
|
||||||
|
// cout << s << '\n';
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
23
advent_of_code/2022/7/test.txt
Normal file
23
advent_of_code/2022/7/test.txt
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user