parent
bfa9abdc5c
commit
ecb5fc9f06
4 changed files with 70 additions and 4 deletions
@ -1,9 +1,46 @@ |
||||
#include "Day06.h" |
||||
|
||||
Result Day06::Task1() { |
||||
return Day::Task1(); |
||||
uint64 product = 1; |
||||
|
||||
for (auto &[time, distance] : parseRecords()){ |
||||
uint64 wins = 0; |
||||
for (uint64 holdTime = 1; holdTime < time; holdTime++) |
||||
if ((time - holdTime) * holdTime > distance) wins++; |
||||
product *= wins; |
||||
} |
||||
|
||||
return to_string(product); |
||||
} |
||||
|
||||
Result Day06::Task2() { |
||||
return Day::Task2(); |
||||
} |
||||
auto [time, distance] = parseRecord(); |
||||
|
||||
uint64 wins = 0; |
||||
for (uint64 holdTime = 1; holdTime < time; holdTime++) |
||||
if ((time - holdTime) * holdTime > distance) wins++; |
||||
|
||||
return to_string(wins); |
||||
} |
||||
|
||||
vector<Day06::Record> Day06::parseRecords() const { |
||||
vector<Record> records; |
||||
|
||||
vector<uint64> time = parseInts(input[0].substr(5)); |
||||
vector<uint64> distance = parseInts(input[1].substr(10)); |
||||
|
||||
for (size_t i = 0; i < time.size(); i++) |
||||
records.emplace_back(time[i], distance[i]); |
||||
|
||||
return records; |
||||
} |
||||
|
||||
Day06::Record Day06::parseRecord() const { |
||||
string rawTime = input[0].substr(10); |
||||
std::erase(rawTime, ' '); |
||||
string rawDistance = input[1].substr(10); |
||||
std::erase(rawDistance, ' '); |
||||
uint64 time = std::stoul(rawTime); |
||||
uint64 distance = std::stoul(rawDistance); |
||||
return {time, distance}; |
||||
} |
||||
|
Loading…
Reference in new issue