Change long long int to fixed width integer type int64_t

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

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_;
}