Change long long int to fixed width integer type int64_t

This commit is contained in:
Stefan Müller 2025-05-22 16:12:56 +02:00
parent 97b61836d8
commit 0b70db7670
35 changed files with 93 additions and 96 deletions

View File

@ -20,7 +20,7 @@
#include <aoc/framework/Solver-types.hpp>
class BridgeRepair
: public Solver<long long, long long>
: public Solver<int64_t, int64_t>
{
public:
virtual const std::string getPuzzleName() const override;
@ -28,6 +28,6 @@ class BridgeRepair
virtual void processDataLine(const std::string& line) override;
virtual void finish() override;
private:
bool testCalibration(const long long int testValue, const std::vector<std::pair<int, int>>& calibrationNumbers,
const size_t currentIndex, const bool allowConcatenation, const long long int accumulatedTestValue);
bool testCalibration(const int64_t testValue, const std::vector<std::pair<int, int>>& calibrationNumbers,
const size_t currentIndex, const bool allowConcatenation, const int64_t accumulatedTestValue);
};

View File

@ -20,7 +20,7 @@
#include <aoc/framework/LinesSolver-types.hpp>
class CeresSearch
: public LinesSolver<long long, long long>
: public LinesSolver<int64_t, int64_t>
{
public:
virtual const std::string getPuzzleName() const override;

View File

@ -24,7 +24,7 @@
#include <aoc/framework/Solver-types.hpp>
class ChronospatialComputer
: public Solver<std::string, long long>
: public Solver<std::string, int64_t>
{
public:
ChronospatialComputer();
@ -37,5 +37,5 @@ class ChronospatialComputer
std::array<std::unique_ptr<ChronospatialComputerInstruction>, 8> instructions_;
std::vector<int> program_;
ChronospatialComputerState state_;
long long findQuineState();
int64_t findQuineState();
};

View File

@ -19,7 +19,7 @@
#include <aoc/framework/Solver-types.hpp>
class ClawContraption
: public Solver<long long, long long>
: public Solver<int64_t, int64_t>
{
public:
virtual const std::string getPuzzleName() const override;
@ -32,7 +32,7 @@ class ClawContraption
static constexpr int getNMaxButtonPushes();
static constexpr int getButtonACost();
static constexpr int getButtonBCost();
static constexpr long long int getConversionCorrection();
long long int calcTokenCost(const Point2& buttonA, const Point2& buttonB, const Point2& prize,
const long long int offset);
static constexpr int64_t getConversionCorrection();
int64_t calcTokenCost(const Point2& buttonA, const Point2& buttonB, const Point2& prize,
const int64_t offset);
};

View File

@ -22,7 +22,7 @@
#include <aoc/framework/Solver-types.hpp>
class DiskFragmenter
: public Solver<long long, long long>
: public Solver<int64_t, int64_t>
{
public:
virtual const std::string getPuzzleName() const override;
@ -41,5 +41,5 @@ class DiskFragmenter
void keepBackFile(const std::string& line, size_t& back, size_t& backIdNumber, const int nBackBlocks,
size_t& position);
unsigned int getDigit(const std::string& line, const size_t index) const;
long long int calcChecksumPart(const size_t idNumber, const int nBlocks, size_t& position) const;
int64_t calcChecksumPart(const size_t idNumber, const int nBlocks, size_t& position) const;
};

View File

@ -22,7 +22,7 @@
#include <aoc/framework/LinesSolver.hpp>
class GardenGroups
: public LinesSolver<long long, long long>
: public LinesSolver<int64_t, int64_t>
{
public:
GardenGroups(const int inputFileNameSuffix = 0);

View File

@ -23,7 +23,7 @@
#include <aoc/framework/LinesSolver.hpp>
class GuardGallivant
: public LinesSolver<long long, long long>
: public LinesSolver<int64_t, int64_t>
{
public:
virtual const std::string getPuzzleName() const override;

View File

@ -20,7 +20,7 @@
#include <aoc/framework/Solver-types.hpp>
class HistorianHysteria
: public Solver<long long, long long>
: public Solver<int64_t, int64_t>
{
public:
virtual const std::string getPuzzleName() const override;

View File

@ -21,7 +21,7 @@
#include <aoc/framework/LinesSolver.hpp>
class HoofIt
: public LinesSolver<long long, long long>
: public LinesSolver<int64_t, int64_t>
{
public:
virtual const std::string getPuzzleName() const override;

View File

@ -19,7 +19,7 @@
#include <aoc/framework/Solver-types.hpp>
class LanParty
: public Solver<long long, std::string>
: public Solver<int64_t, std::string>
{
public:
virtual const std::string getPuzzleName() const override;

View File

@ -20,7 +20,7 @@
#include <aoc/framework/Solver-types.hpp>
class MullItOver
: public Solver<long long, long long>
: public Solver<int64_t, int64_t>
{
public:
MullItOver();

View File

@ -21,7 +21,7 @@
#include <aoc/framework/Solver-types.hpp>
class PlutonianPebbles
: public Solver<long long, long long>
: public Solver<int64_t, int64_t>
{
public:
virtual const std::string getPuzzleName() const override;
@ -31,9 +31,8 @@ class PlutonianPebbles
private:
static constexpr int getNBlinksPart1();
static constexpr int getNBlinksPart2();
std::map<long long int, std::vector<long long int>> blinkMap_{};
void addPebble(std::map<long long int, long long int>& pebbles, const long long int pebbleNumber,
long long int cardinality);
void addNextBlinkNumbers(const long long int pebbleNumber, std::vector<long long int>& nextBlinkNumbers);
int getNNextBlinkNumbers(const long long int pebbleNumber) const;
std::map<int64_t, std::vector<int64_t>> blinkMap_{};
void addPebble(std::map<int64_t, int64_t>& pebbles, const int64_t pebbleNumber, int64_t cardinality);
void addNextBlinkNumbers(const int64_t pebbleNumber, std::vector<int64_t>& nextBlinkNumbers);
int getNNextBlinkNumbers(const int64_t pebbleNumber) const;
};

View File

@ -21,7 +21,7 @@
#include <aoc/framework/Solver-types.hpp>
class PrintQueue
: public Solver<long long, long long>
: public Solver<int64_t, int64_t>
{
public:
PrintQueue();

View File

@ -20,7 +20,7 @@
#include <aoc/framework/Solver-types.hpp>
class RedNosedReports
: public Solver<long long, long long>
: public Solver<int64_t, int64_t>
{
public:
virtual const std::string getPuzzleName() const override;

View File

@ -26,7 +26,7 @@
#include <aoc/framework/LinesSolver.hpp>
class ReindeerMaze
: public LinesSolver<long long, long long>
: public LinesSolver<int64_t, int64_t>
{
public:
ReindeerMaze(const int inputFileNameSuffix = 0);

View File

@ -23,7 +23,7 @@
#include <aoc/framework/LinesSolver.hpp>
class ResonantCollinearity
: public LinesSolver<long long, long long>
: public LinesSolver<int64_t, int64_t>
{
public:
virtual const std::string getPuzzleName() const override;
@ -35,5 +35,5 @@ class ResonantCollinearity
void addNewAntenna(Grid<bool>& antinodeGrid1, Grid<bool>& antinodeGrid2, Point2&& newPosition);
void findNewAntinodes(Grid<bool>& antinodeGrid1, Grid<bool>& antinodeGrid2, Point2&& start,
const Point2& increment);
void addNewAntinode(Grid<bool>& antinodeGrid, Point2& newPosition, long long int& part);
void addNewAntinode(Grid<bool>& antinodeGrid, Point2& newPosition, int64_t& part);
};

View File

@ -22,7 +22,7 @@
#include <aoc/framework/Solver-types.hpp>
class RestroomRedoubt
: public Solver<long long, long long>
: public Solver<int64_t, int64_t>
{
public:
RestroomRedoubt(const int width = 101, const int height = 103, const bool runPart2 = true);

View File

@ -21,7 +21,7 @@
#include <aoc/framework/LinesSolver-types.hpp>
class WarehouseWoes
: public LinesSolver<long long, long long>
: public LinesSolver<int64_t, int64_t>
{
public:
WarehouseWoes(const int inputFileNameSuffix = 0);
@ -43,6 +43,6 @@ class WarehouseWoes
static constexpr char getEmptyChar();
void checkStartingPosition(const std::string& line);
void addWarehouseMap2Line(const std::string& line);
long long int calcAllGpsCoordinates(Lines& warehouseMap, const char boxChar);
long long int calcGpsCoordinate(const size_t x, const size_t y);
int64_t calcAllGpsCoordinates(Lines& warehouseMap, const char boxChar);
int64_t calcGpsCoordinate(const size_t x, const size_t y);
};

View File

@ -30,7 +30,7 @@ class ChronospatialComputerInstruction
protected:
virtual void runValue(ChronospatialComputerState& state, const int operandValue) const = 0;
private:
std::function<int(const std::array<long long, 3>&, const int)> operandFunctor_;
std::function<int(const std::array<int64_t, 3>&, const int)> operandFunctor_;
};
#pragma region ChronospatialComputerDivisionInstruction

View File

@ -22,6 +22,6 @@ class ChronospatialComputerState
{
public:
size_t instructionPointer{ 0 };
std::array<long long, 3> registers{};
std::array<int64_t, 3> registers{};
std::ostringstream output{};
};

View File

@ -15,6 +15,8 @@
#pragma once
#include <cstdint>
class MullData
{
public:
@ -24,12 +26,12 @@ class MullData
int getFactor(const int index) const;
void setFactor(const int index, const int value);
void updateResult();
long long int getResultPart1() const;
long long int getResultPart2() const;
int64_t getResultPart1() const;
int64_t getResultPart2() const;
private:
bool isEnabled_;
int factor1_;
int factor2_;
long long int part1_;
long long int part2_;
int64_t part1_;
int64_t part2_;
};

View File

@ -15,4 +15,4 @@
#include <aoc/framework/LinesSolver-impl.hpp>
template class LinesSolver<long long, long long>;
template class LinesSolver<int64_t, int64_t>;

View File

@ -17,6 +17,6 @@
#include <string>
template class Solver<long long, long long>;
template class Solver<long long, std::string>;
template class Solver<int64_t, int64_t>;
template class Solver<int64_t, std::string>;
template class Solver<std::string, std::string>;

View File

@ -34,7 +34,7 @@ void BridgeRepair::processDataLine(const std::string& line)
{
std::istringstream stream{ line };
long long int testValue;
int64_t testValue;
char colon;
int calibrationNumber;
// Calibration numbers are a pair of an actual calibration number and its precomputed smallest larger power of 10.
@ -68,14 +68,13 @@ void BridgeRepair::finish()
{
}
bool BridgeRepair::testCalibration(const long long int testValue,
const std::vector<std::pair<int, int>>& calibrationNumbers, const size_t currentIndex,
const bool allowConcatenation, const long long int accumulatedTestValue)
bool BridgeRepair::testCalibration(const int64_t testValue, const std::vector<std::pair<int, int>>& calibrationNumbers,
const size_t currentIndex, const bool allowConcatenation, const int64_t accumulatedTestValue)
{
if (testValue >= accumulatedTestValue && currentIndex < calibrationNumbers.size())
{
size_t nextIndex{ currentIndex + 1 };
long long int nextCalibrationNumber{ calibrationNumbers[currentIndex].first };
int64_t nextCalibrationNumber{ calibrationNumbers[currentIndex].first };
// Recursively tries the ||, *, and + operators.
if ((allowConcatenation && testCalibration(testValue, calibrationNumbers, nextIndex, allowConcatenation,
accumulatedTestValue * calibrationNumbers[currentIndex].second + calibrationNumbers[currentIndex].first)) ||

View File

@ -85,7 +85,7 @@ void ChronospatialComputer::runProgram(const std::vector<int>& program, Chronosp
}
}
long long ChronospatialComputer::findQuineState()
int64_t ChronospatialComputer::findQuineState()
{
// The following masks and output patterns are specific to a single program and have been precalculated manually.
// The given Chronospatial Computer program essentially does the following calculations.
@ -126,7 +126,7 @@ long long ChronospatialComputer::findQuineState()
{ { 2, 0b001 }, { 3, 0b00 }, { 4, 0b11100 }, { 5, 0b1100 }, { 6, 0b1010000 }, { 7, 0b100000 } }
} };
long long result{ 0 };
int64_t result{ 0 };
size_t i{ program_.size() };
int lastAppend{ -1 };

View File

@ -85,23 +85,23 @@ constexpr int ClawContraption::getButtonBCost()
return 1;
}
constexpr long long int ClawContraption::getConversionCorrection()
constexpr int64_t ClawContraption::getConversionCorrection()
{
return 10000000000000;
}
long long int ClawContraption::calcTokenCost(const Point2& buttonA, const Point2& buttonB, const Point2& prize,
const long long int offset)
int64_t ClawContraption::calcTokenCost(const Point2& buttonA, const Point2& buttonB, const Point2& prize,
const int64_t offset)
{
long long int p{ (prize.y + offset) * buttonB.x - (prize.x + offset) * buttonB.y };
long long int q{ buttonA.y * buttonB.x - buttonA.x * buttonB.y };
long long int a{ p / q };
int64_t p{ (prize.y + offset) * buttonB.x - (prize.x + offset) * buttonB.y };
int64_t q{ buttonA.y * buttonB.x - buttonA.x * buttonB.y };
int64_t a{ p / q };
if (a * q != p || (offset == 0 && a > getNMaxButtonPushes()))
{
return 0;
}
long long int r{ prize.x + offset - a * buttonA.x };
long long int b{ r / buttonB.x };
int64_t r{ prize.x + offset - a * buttonA.x };
int64_t b{ r / buttonB.x };
if (b * buttonB.x != r || (offset == 0 && b > getNMaxButtonPushes()))
{
return 0;

View File

@ -196,10 +196,9 @@ unsigned int DiskFragmenter::getDigit(const std::string& line, const size_t inde
return line[index] - '0';
}
long long int DiskFragmenter::calcChecksumPart(const size_t idNumber, const int nBlocks, size_t& position) const
int64_t DiskFragmenter::calcChecksumPart(const size_t idNumber, const int nBlocks, size_t& position) const
{
position += nBlocks;
// Casting the parameters is required to allow negative block count, resulting in a negative return value.
return static_cast<long long int>(idNumber) *
((nBlocks * (2 * static_cast<long long int>(position) - nBlocks - 1)) / 2);
return static_cast<int64_t>(idNumber) * ((nBlocks * (2 * static_cast<int64_t>(position) - nBlocks - 1)) / 2);
}

View File

@ -51,9 +51,9 @@ void GardenGroups::finish()
void GardenGroups::traverseRegion(Grid<bool>& isVisited, std::stack<Point2>& otherRegionsStack, const Point2& start)
{
const char plantType{ getCharAt(start) };
long long int area{ 0 };
long long int perimeter{ 0 };
long long int nCorners{ 0 };
int64_t area{ 0 };
int64_t perimeter{ 0 };
int64_t nCorners{ 0 };
std::stack<Point2> regionStack{};
regionStack.push(start);

View File

@ -31,13 +31,13 @@ const int PlutonianPebbles::getPuzzleDay() const
void PlutonianPebbles::processDataLine(const std::string& line)
{
// Maps pebble numbers before the blink to their cardinality.
auto currentPebbles = std::make_shared<std::map<long long int, long long int>>();
auto currentPebbles = std::make_shared<std::map<int64_t, int64_t>>();
// Maps pebble numbers after the blink to their cardinality.
std::shared_ptr<std::map<long long int, long long int>> nextBlinkPebbles;
std::shared_ptr<std::map<int64_t, int64_t>> nextBlinkPebbles;
// Adds initial pebbles numbers.
std::istringstream stream{ line };
long long int pebbleNumber;
int64_t pebbleNumber;
while (stream >> pebbleNumber)
{
addPebble(*currentPebbles, pebbleNumber, 1);
@ -47,7 +47,7 @@ void PlutonianPebbles::processDataLine(const std::string& line)
for (int i = getNBlinksPart2(); i > 1; i--)
{
// Maps pebble numbers after the blink to their cardinality.
nextBlinkPebbles = std::make_shared<std::map<long long int, long long int>>();
nextBlinkPebbles = std::make_shared<std::map<int64_t, int64_t>>();
for (const auto& pebble : *currentPebbles)
{
@ -107,8 +107,7 @@ constexpr int PlutonianPebbles::getNBlinksPart2()
return 75;
}
void PlutonianPebbles::addPebble(std::map<long long int, long long int>& pebbles, const long long int pebbleNumber,
long long int cardinality)
void PlutonianPebbles::addPebble(std::map<int64_t, int64_t>& pebbles, const int64_t pebbleNumber, int64_t cardinality)
{
auto hit = pebbles.find(pebbleNumber);
if (hit == pebbles.end())
@ -121,8 +120,7 @@ void PlutonianPebbles::addPebble(std::map<long long int, long long int>& pebbles
}
}
void PlutonianPebbles::addNextBlinkNumbers(const long long int pebbleNumber,
std::vector<long long int>& nextBlinkNumbers)
void PlutonianPebbles::addNextBlinkNumbers(const int64_t pebbleNumber, std::vector<int64_t>& nextBlinkNumbers)
{
if (pebbleNumber == 0)
{
@ -144,7 +142,7 @@ void PlutonianPebbles::addNextBlinkNumbers(const long long int pebbleNumber,
}
}
int PlutonianPebbles::getNNextBlinkNumbers(const long long int pebbleNumber) const
int PlutonianPebbles::getNNextBlinkNumbers(const int64_t pebbleNumber) const
{
auto s = std::to_string(pebbleNumber);
if (s.size() % 2 == 0)

View File

@ -91,7 +91,7 @@ void ResonantCollinearity::findNewAntinodes(Grid<bool>& antinodeGrid1, Grid<bool
}
}
void ResonantCollinearity::addNewAntinode(Grid<bool>& antinodeGrid, Point2& newPosition, long long int& count)
void ResonantCollinearity::addNewAntinode(Grid<bool>& antinodeGrid, Point2& newPosition, int64_t& count)
{
if (!antinodeGrid[newPosition.y][newPosition.x])
{

View File

@ -125,9 +125,9 @@ void WarehouseWoes::addWarehouseMap2Line(const std::string& line)
lines2_.push_back(stream.str());
}
long long int WarehouseWoes::calcAllGpsCoordinates(Lines& warehouseMap, const char boxChar)
int64_t WarehouseWoes::calcAllGpsCoordinates(Lines& warehouseMap, const char boxChar)
{
long long int result{ 0 };
int64_t result{ 0 };
for (size_t j = 0; j < warehouseMap.size(); j++)
{
for (size_t i = 0; i < warehouseMap[j].size(); i++)
@ -141,7 +141,7 @@ long long int WarehouseWoes::calcAllGpsCoordinates(Lines& warehouseMap, const ch
return result;
}
long long int WarehouseWoes::calcGpsCoordinate(const size_t x, const size_t y)
int64_t WarehouseWoes::calcGpsCoordinate(const size_t x, const size_t y)
{
return x + 100 * y;
}

View File

@ -22,10 +22,10 @@ ChronospatialComputerInstruction::ChronospatialComputerInstruction(const Chronos
switch (type)
{
case ChronospatialComputerOperandType::Literal :
operandFunctor_ = [](const std::array<long long, 3>& registers, const int operand) { return operand; };
operandFunctor_ = [](const std::array<int64_t, 3>& registers, const int operand) { return operand; };
break;
case ChronospatialComputerOperandType::Combo :
operandFunctor_ = [](const std::array<long long, 3>& registers, const int operand)
operandFunctor_ = [](const std::array<int64_t, 3>& registers, const int operand)
{ return operand < 4 ? operand : registers[static_cast<size_t>(operand - 4)]; };
break;
}

View File

@ -57,12 +57,12 @@ void MullData::updateResult()
}
}
long long int MullData::getResultPart1() const
int64_t MullData::getResultPart1() const
{
return part1_;
}
long long int MullData::getResultPart2() const
int64_t MullData::getResultPart2() const
{
return part2_;
}

View File

@ -27,17 +27,17 @@
class TestContext
{
public:
void run(std::unique_ptr<Solver<long long, long long>>&& solver, const long long& expected1,
const long long& expected2, const std::vector<std::string>& inputPaths);
void run(std::unique_ptr<Solver<long long, std::string>>&& solver, const long long& expected1,
void run(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected1, const int64_t expected2,
const std::vector<std::string>& inputPaths);
void run(std::unique_ptr<Solver<int64_t, std::string>>&& solver, const int64_t expected1,
const std::string& expected2, const std::vector<std::string>& inputPaths);
void run(std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string& expected1,
const long long& expected2, const std::vector<std::string>& inputPaths);
void runPart1(std::unique_ptr<Solver<long long, long long>>&& solver, const long long& expected,
void run(std::unique_ptr<Solver<std::string, int64_t>>&& solver, const std::string& expected1,
const int64_t expected2, const std::vector<std::string>& inputPaths);
void runPart1(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected,
const std::vector<std::string>& inputPaths);
void runPart1(std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string& expected,
void runPart1(std::unique_ptr<Solver<std::string, int64_t>>&& solver, const std::string& expected,
const std::vector<std::string>& inputPaths);
void runPart2(std::unique_ptr<Solver<long long, long long>>&& solver, const long long& expected,
void runPart2(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected,
const std::vector<std::string>& inputPaths);
std::vector<std::string> getInputPaths() const;
std::vector<std::string> getExampleInputPaths() const;

View File

@ -15,37 +15,37 @@
#include <aocTests/TestContext.hpp>
void TestContext::run(std::unique_ptr<Solver<long long, long long>>&& solver, const long long& expected1,
const long long& expected2, const std::vector<std::string>& inputPaths)
void TestContext::run(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected1,
const int64_t expected2, const std::vector<std::string>& inputPaths)
{
runGeneric(std::move(solver), expected1, expected2, inputPaths);
}
void TestContext::run(std::unique_ptr<Solver<long long, std::string>>&& solver, const long long& expected1,
void TestContext::run(std::unique_ptr<Solver<int64_t, std::string>>&& solver, const int64_t expected1,
const std::string& expected2, const std::vector<std::string>& inputPaths)
{
runGeneric(std::move(solver), expected1, expected2, inputPaths);
}
void TestContext::run(std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string& expected1,
const long long& expected2, const std::vector<std::string>& inputPaths)
void TestContext::run(std::unique_ptr<Solver<std::string, int64_t>>&& solver, const std::string& expected1,
const int64_t expected2, const std::vector<std::string>& inputPaths)
{
runGeneric(std::move(solver), expected1, expected2, inputPaths);
}
void TestContext::runPart1(std::unique_ptr<Solver<long long, long long>>&& solver, const long long& expected,
void TestContext::runPart1(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected,
const std::vector<std::string>& inputPaths)
{
runPart1Generic(std::move(solver), expected, inputPaths);
}
void TestContext::runPart1(std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string& expected,
void TestContext::runPart1(std::unique_ptr<Solver<std::string, int64_t>>&& solver, const std::string& expected,
const std::vector<std::string>& inputPaths)
{
runPart1Generic(std::move(solver), expected, inputPaths);
}
void TestContext::runPart2(std::unique_ptr<Solver<long long, long long>>&& solver, const long long& expected,
void TestContext::runPart2(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected,
const std::vector<std::string>& inputPaths)
{
runPart2Generic(std::move(solver), expected, inputPaths);