Skip to content

Commit

Permalink
of course part 2 is hard...
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Dec 12, 2024
1 parent 7c13f6f commit 742b186
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions 2024/src/day11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ Node *get_node(uint64_t new_value, std::map<uint64_t, std::unique_ptr<Node>> &sp
return splits[new_value].get();
}

uint64_t part1(const Data &data)
{
uint64_t count_stones(int blinks, const Data& data) {
std::map<uint64_t, std::unique_ptr<Node>> splits;
uint64_t sum = 0;

Expand All @@ -41,17 +40,16 @@ uint64_t part1(const Data &data)
std::queue<std::pair<uint64_t, uint64_t>> q;
q.push({stone, 0});
sum += 1;
uint64_t n_steps = 25;

while (!q.empty())
{
auto val = q.front();
Node *cur = get_node(val.first, splits);


for (size_t blink = val.second; blink < n_steps; ++blink)
for (size_t blink = val.second; blink < blinks; ++blink)
{
while (cur->left != nullptr && blink < n_steps)
while (cur->left != nullptr && blink < blinks)
{
if (cur->right != nullptr)
{
Expand All @@ -61,7 +59,7 @@ uint64_t part1(const Data &data)
++blink;
cur = cur->left;
}
if (blink >= n_steps)
if (blink >= blinks)
break;
uint64_t num_digits = std::floor(std::log10(cur->value)) + 1;
if (cur->value == 0)
Expand Down Expand Up @@ -96,9 +94,14 @@ uint64_t part1(const Data &data)
return sum;
}

int part2(const Data &data)
uint64_t part1(const Data &data)
{
return count_stones(25, data);
}

uint64_t part2(const Data &data)
{
return 0;
return count_stones(75, data);
}

Data parse()
Expand Down Expand Up @@ -143,7 +146,7 @@ BENCHMARK_DEFINE_F(BenchmarkFixture, Part2Benchmark)
{
for (auto _ : state)
{
int s = part2(data);
uint64_t s = part2(data);
benchmark::DoNotOptimize(s);
}
}
Expand All @@ -155,8 +158,8 @@ int main(int argc, char **argv)
{
Data data = parse();

uint64_t answer1 = 0;
int answer2 = 0;
uint64_t answer1 = 198089;
uint64_t answer2 = 0;

auto first = part1(data);
std::cout << "Part 1: " << first << std::endl;
Expand Down

0 comments on commit 742b186

Please sign in to comment.