Repository navigation
Expand file tree
/
Copy pathAssignment7.cpp
More file actions
114 lines (98 loc) · 2.28 KB
/
Copy pathAssignment7.cpp
File metadata and controls
114 lines (98 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "AdventClass.h"
#include "FileUtility.h"
#include "LimitFunctions.h"
#include <set>
#include "LimitFunctions.h"
class TestAssignment7 : public TAdventClass
{
};
TEST_F(TestAssignment7, TestDaySeven)
{
struct TFile {
wxString Name;
wxInt64 Size;
};
struct TDirectory {
public:
TDirectory(const wxString& Name) {
this->Name = Name;
}
wxString Name;
TCVector<TFile> Files;
TCVector<TDirectory*> Directories;
void AddFile(const wxInt64 Size, const wxString& Name)
{
Files.push_back({ Name, Size });
}
void DirSize(TCVector<TFile>* DirSizes) const
{
wxInt64 Total = 0;
for (auto& File : Files)
{
Total += File.Size;
}
for (auto& Dir : Directories)
{
Dir->DirSize(DirSizes);
Total += DirSizes->back().Size;
}
DirSizes->Add({ Name, Total });
}
};
TCVector<TDirectory*> FileSystem;
auto Input = ReadFileLines(RealInput());
TCVector<TDirectory*> Stack;
for (auto& Line : Input)
{
if (Line.StartsWith("$ cd /"))
{
Stack.push_back(new TDirectory("root"));
}
else if (Line.StartsWith("$ cd .."))
{
Stack.pop_back();
}
else if (Line.StartsWith("$ cd"))
{
Stack.push_back(Stack.back()->Directories.Add(new TDirectory(Stack.back()->Name + "." + Line.substr(5))));
}
else if (Line.StartsWith("$ ls"))
{
continue;
}
else if (Line.StartsWith("dir"))
{
continue;
}
else
{
auto Info = Split(Line, " ");
Stack.back()->AddFile(StringToInt<wxInt32>(Info[0]), Info[1]);
}
}
wxInt64 Sum = 0;
TCVector<TFile> Items;
Stack.front()->DirSize(&Items);
for (auto& Item : Items)
{
RecordProperty(wxString("Dir ") + Item.Name + ", Size: " + Item.Size);
if (Item.Size <= 100000) {
Sum += Item.Size;
}
}
RecordProperty("Sum of dirs: ", Sum);
auto TotalSpace = 70000000;
auto MaxOccupied = 30000000;
auto TotalSize = 44804833;
auto CurrentFree = TotalSpace - TotalSize;
auto RequiredSize = MaxOccupied - CurrentFree;
auto TheFolder = wxINT64_MAX;
for (auto& Item : Items)
{
if (Item.Size >= RequiredSize)
{
TheFolder = Minimum(TheFolder, Item.Size);
}
}
RecordProperty("Folder dize:", TheFolder);
}