Add solution for "Day 22: Monkey Market", part 1
This commit is contained in:
52
src/MonkeyMarket.cpp
Normal file
52
src/MonkeyMarket.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2025 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <aoc/MonkeyMarket.hpp>
|
||||
|
||||
const std::string MonkeyMarket::getPuzzleName() const
|
||||
{
|
||||
return "Monkey Market";
|
||||
}
|
||||
|
||||
const int MonkeyMarket::getPuzzleDay() const
|
||||
{
|
||||
return 22;
|
||||
}
|
||||
|
||||
void MonkeyMarket::processDataLine(const std::string& line)
|
||||
{
|
||||
uint64_t n{ std::stoull(line) };
|
||||
for (int i = 0; i < getNSecretNumbers(); i++)
|
||||
{
|
||||
n = ((n << 6) ^ n) & getPruneValue();
|
||||
n = (n >> 5) ^ n;
|
||||
n = ((n << 11) ^ n) & getPruneValue();
|
||||
}
|
||||
part1 += n;
|
||||
}
|
||||
|
||||
void MonkeyMarket::finish()
|
||||
{
|
||||
}
|
||||
|
||||
constexpr int MonkeyMarket::getNSecretNumbers()
|
||||
{
|
||||
return 2000;
|
||||
}
|
||||
|
||||
constexpr uint64_t MonkeyMarket::getPruneValue()
|
||||
{
|
||||
return 16777215;
|
||||
}
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <aoc/LinenLayout.hpp>
|
||||
#include <aoc/RaceCondition.hpp>
|
||||
#include <aoc/KeypadConundrum.hpp>
|
||||
#include <aoc/MonkeyMarket.hpp>
|
||||
#include <aoc/LanParty.hpp>
|
||||
|
||||
void Program::run()
|
||||
@@ -81,6 +82,7 @@ void Program::runSolvers()
|
||||
runSolver<LinenLayout>(solverEngine);
|
||||
runSolver<RaceCondition>(solverEngine);
|
||||
runSolver<KeypadConundrum>(solverEngine);
|
||||
runSolver<MonkeyMarket>(solverEngine);
|
||||
runSolver<LanParty>(solverEngine);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user