Repository navigation
Expand file tree
/
Copy pathAssignment19.cpp
More file actions
146 lines (125 loc) · 3.84 KB
/
Copy pathAssignment19.cpp
File metadata and controls
146 lines (125 loc) · 3.84 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "AdventClass.h"
#include "FileUtility.h"
#include "LimitFunctions.h"
#include "StringFunctions.h"
#include "StringHandler.h"
class TestAssignment19 : public TAdventClass
{
public:
class TRobot
{
public:
TRobot(std::initializer_list<wxInt32> Items)
{
Cost = Items;
}
TCVector<wxInt32> Cost;
wxInt32 Amount = 0;
};
class TBluePrint
{
public:
TBluePrint(const wxString& Line)
{
auto Items = Split(Line, ".");
auto First = Split(Items[0], ":");
StringToInt(First[0], &ID);
Robots.push_back(TRobot({ StringToInt<wxInt32>(First[1]) }));
Robots.push_back(TRobot({ StringToInt<wxInt32>(Items[1]) }));
auto Tokens = Split(Items[2], " ");
Robots.push_back(TRobot({ StringToInt<wxInt32>(Tokens[4]), StringToInt<wxInt32>(Tokens[7]) }));
Tokens = Split(Items[3], " ");
Robots.push_back(TRobot({ StringToInt<wxInt32>(Tokens[4]), StringToInt<wxInt32>(Tokens[7]) }));
Robots[0].Amount++;
MaxClay = Robots[2].Cost[1];
MaxOre = std::max({ Robots[1].Cost[0], Robots[2].Cost[0], Robots[3].Cost[0] });
}
wxString ProcessDay(void)
{
TCVector<wxInt32> Delta(4, 0);
if ((Robots[3].Cost[1] <= Obsidian) &&
(Robots[3].Cost[0] <= Ore))
{
Obsidian -= Robots[3].Cost[1];
Ore -= Robots[3].Cost[0];
Delta[3]++;
}
else if ((Robots[2].Cost[1] <= Clay) &&
(Robots[2].Cost[0] <= Ore))
{
Clay -= Robots[2].Cost[1];
Ore -= Robots[2].Cost[0];
Delta[2]++;
}
else if ((Robots[1].Cost[0] <= Ore)
&& (Robots[0].Amount >= Robots[1].Cost[0])
&& (Robots[1].Amount <= MaxClay))
{
Ore -= Robots[1].Cost[0];
Delta[1]++;
}
else if ((Robots[0].Cost[0] <= Ore)
&& (Robots[0].Amount < MaxOre))
{
Ore -= Robots[0].Cost[0];
Delta[0]++;
}
Ore += Robots[0].Amount;
Clay += Robots[1].Amount;
Obsidian += Robots[2].Amount;
Geode += Robots[3].Amount;
for (auto Iterator = 0 ; 4 > Iterator ; ++Iterator)
{
Robots[Iterator].Amount += Delta[Iterator];
}
return wxString::Format("Total: Ore %i, Clay %i, Obsidian %i, Geode %i. OreMiner %i, ClayMiner %i, ObsidianMinder %i, GeodeMinder %i"\
, Ore, Clay, Obsidian, Geode, Robots[0].Amount, Robots[1].Amount, Robots[2].Amount, Robots[3].Amount);
}
wxInt32 QualityValue(void) const
{
return ID * Geode;
}
wxDouble GeodeToOreRatio(void)
{
TotalOre = Robots[3].Cost[0] + Robots[3].Cost[1] * Robots[2].Cost[0];
TotalClay = Robots[3].Cost[1] * Robots[2].Cost[1];
return wxDouble(TotalClay) / wxDouble(TotalOre);
}
wxInt32 ID;
TCVector<TRobot> Robots;
wxInt32 Clay = 0;
wxInt32 Ore = 0;
wxInt32 Obsidian = 0;
wxInt32 Geode = 0;
wxInt32 TotalOre = 0;
wxInt32 TotalClay = 0;
wxInt32 MaxOre = 0;
wxInt32 MaxClay = 0;
};
TCVector<TBluePrint> Factory;
};
TEST_F(TestAssignment19, TestDayOne)
{
for (auto& Line : ReadFileLines(RealInput()))
{
Factory.push_back(TBluePrint(Line));
RecordProperty("Ratio: ", wxString("Clay: ") + Factory.back().TotalClay + ", Ore: " + Factory.back().TotalOre);
if (Factory.size() == 3)
{
break;
}
}
auto TotalQuality = 0;
TCVector<wxInt32> TotalGeodes;
for (auto& Item : Factory)
{
for (auto Minutes = 0; 32 > Minutes; ++Minutes)
{
RecordProperty(wxString::Format("Running day %i. %s", Minutes, Item.ProcessDay()));
}
TotalQuality += RecordProperty("Quality of this ID: ", Item.QualityValue());
TotalGeodes.push_back(RecordProperty("Opened Geodes of this factory: " , Item.Geode));
}
RecordProperty("Total Quality: ", TotalQuality);
RecordProperty("Total geodes: ", TotalGeodes[0] * TotalGeodes[1] * TotalGeodes[2]);
}