Fixed indentation

main
Benjamin Kraft 9 months ago
parent 3223948f51
commit bfa9abdc5c
  1. 3
      src/days/01/Day01.cpp
  2. 6
      src/days/03/Day03.cpp
  3. 6
      src/days/04/Day04.cpp
  4. 11
      src/days/05/Day05.h
  5. 3
      src/main.cpp

@ -7,7 +7,8 @@ Result Day01::Task1() {
int diff = c - '0'; int diff = c - '0';
return diff >= 0 && diff < 10; return diff >= 0 && diff < 10;
}) - '0'; }) - '0';
uint8_t right = *std::find_if(std::make_reverse_iterator(line.end()), std::make_reverse_iterator(line.begin()), [](const char c){ uint8_t right = *std::find_if(std::make_reverse_iterator(line.end()), std::make_reverse_iterator(line.begin()),
[](const char c) {
int diff = c - '0'; int diff = c - '0';
return diff >= 0 && diff < 10; return diff >= 0 && diff < 10;
}) - '0'; }) - '0';

@ -87,10 +87,12 @@ vector<Day03::EngineNumber> Day03::parseEngineNumbers() const {
valueLength++; valueLength++;
readingValue = true; readingValue = true;
if (x == line.length() - 1) if (x == line.length() - 1)
numbers.push_back({{value, valueLength}, {x - valueLength, y}}); numbers.push_back({{value, valueLength},
{x - valueLength, y}});
} else { } else {
if (readingValue) if (readingValue)
numbers.push_back({{value, valueLength}, {x - valueLength, y}}); numbers.push_back({{value, valueLength},
{x - valueLength, y}});
readingValue = false; readingValue = false;
valueLength = 0; valueLength = 0;
value = 0; value = 0;

@ -6,7 +6,8 @@ Result Day04::Task1() {
for (const auto &[winning, having]: parseCards()) { for (const auto &[winning, having]: parseCards()) {
std::set<uint8_t> result; std::set<uint8_t> result;
std::set_intersection(winning.begin(), winning.end(), having.begin(), having.end(), std::inserter(result, result.begin())); std::set_intersection(winning.begin(), winning.end(), having.begin(), having.end(),
std::inserter(result, result.begin()));
if (!result.empty()) { if (!result.empty()) {
sum += uint64(powl(2, result.size() - 1)); sum += uint64(powl(2, result.size() - 1));
} }
@ -20,7 +21,8 @@ Result Day04::Task2() {
for (const auto &[winning, having]: parseCards()) { for (const auto &[winning, having]: parseCards()) {
std::set<uint8_t> result; std::set<uint8_t> result;
std::set_intersection(winning.begin(), winning.end(), having.begin(), having.end(), std::inserter(result, result.begin())); std::set_intersection(winning.begin(), winning.end(), having.begin(), having.end(),
std::inserter(result, result.begin()));
matches.push_back(result.size()); matches.push_back(result.size());
} }

@ -7,26 +7,37 @@ class Day05 : public Day {
uint64 start; uint64 start;
uint64 end; uint64 end;
}; };
struct Mapping { struct Mapping {
uint64 destination; uint64 destination;
uint64 source; uint64 source;
uint64 range; uint64 range;
bool containsKey(uint64 src) const; bool containsKey(uint64 src) const;
uint64 get(uint64 src) const; uint64 get(uint64 src) const;
bool touchesRange(Range src) const; bool touchesRange(Range src) const;
Range get(Range src) const; Range get(Range src) const;
bool operator<(const Mapping &other) const; bool operator<(const Mapping &other) const;
}; };
struct Map { struct Map {
set<Mapping> mappings; set<Mapping> mappings;
uint64 get(uint64 src) const; uint64 get(uint64 src) const;
vector<Range> get(Range src) const; vector<Range> get(Range src) const;
}; };
protected: protected:
Result Task1() override; Result Task1() override;
Result Task2() override; Result Task2() override;
vector<uint64> parseSeeds() const; vector<uint64> parseSeeds() const;
std::array<Map, 7> parseMaps() const; std::array<Map, 7> parseMaps() const;
}; };

@ -25,7 +25,8 @@ Input getInput(int day, string key, bool useTestInput, int testFetchIndex) {
file << cpr::Get(cpr::Url{url}, cookies).text; file << cpr::Get(cpr::Url{url}, cookies).text;
file.close(); file.close();
} else { } else {
cout << "Test Input does not exist. Fetching from " + url << " from <code>-Tag with index " << testFetchIndex << endl; cout << "Test Input does not exist. Fetching from " + url << " from <code>-Tag with index "
<< testFetchIndex << endl;
std::ofstream file(localFilePath); std::ofstream file(localFilePath);
string res = cpr::Get(cpr::Url{url}).text; string res = cpr::Get(cpr::Url{url}).text;
size_t i1 = findAll(res, "<code>")[testFetchIndex]; size_t i1 = findAll(res, "<code>")[testFetchIndex];

Loading…
Cancel
Save