Cleaned up day 1-3

This commit is contained in:
Hugo Mårdbrink 2021-12-09 00:44:10 +01:00
parent c295529953
commit ab21e8ad7d
6 changed files with 92 additions and 68 deletions

View file

@ -13,18 +13,16 @@ const void getGammaEpsilon(std::bitset<bSize>& g,
int main()
{
std::vector<std::string> inputs = readToString("../input/03.txt");
std::vector<std::string> rates = readToString("../input/03.txt");
std::bitset<bSize> g, e;
getGammaEpsilon(g, e, inputs);
getGammaEpsilon(g, e, rates);
std::cout << (g.to_ulong() * e.to_ulong()) << std::endl;
return 0;
}
const std::vector<std::string>& readToString(const std::string& path)
{
std::ifstream inputFile(path);
@ -46,10 +44,10 @@ const void getGammaEpsilon(std::bitset<bSize>& g,
int bitOccurence [bSize]{};
for(const auto& el : v)
for(int b = 0; b < bSize; b++)
for(auto b = 0; b < bSize; b++)
bitOccurence[b] += el[b] - 48;
for(int b = 0; b < bSize; b++)
for(auto b = 0; b < bSize; b++)
g.set(bSize-b-1, bitOccurence[b] > v.size()/2);
e = ~g;