Fonctionne ! Et est rapide en comparaison de la version séquentielle de Ben :P
This commit is contained in:
parent
19c3865f80
commit
2fad0776ce
40
main.cpp
40
main.cpp
@ -59,9 +59,11 @@ template<std::size_t ArraySize>
|
|||||||
struct NumberBase26 final {
|
struct NumberBase26 final {
|
||||||
std::array<char, ArraySize> data{};
|
std::array<char, ArraySize> data{};
|
||||||
|
|
||||||
const std::array<char, 26> &alphabet{};
|
static constexpr std::uint32_t valMax{ 26 };
|
||||||
|
|
||||||
static constexpr frozen::unordered_map<char, std::uint32_t, 26> lut = {
|
const std::array<char, valMax> &alphabet{};
|
||||||
|
|
||||||
|
static constexpr frozen::unordered_map<char, std::uint32_t, valMax> lut = {
|
||||||
{ 'A', 0 },
|
{ 'A', 0 },
|
||||||
{ 'B', 1 },
|
{ 'B', 1 },
|
||||||
{ 'C', 2 },
|
{ 'C', 2 },
|
||||||
@ -92,17 +94,35 @@ struct NumberBase26 final {
|
|||||||
|
|
||||||
NumberBase26() = delete;
|
NumberBase26() = delete;
|
||||||
|
|
||||||
explicit NumberBase26(const std::array<char, 26> &_alphabet) : alphabet(_alphabet) {
|
explicit NumberBase26(const std::array<char, valMax> &_alphabet) : alphabet(_alphabet) {
|
||||||
data.fill('A');
|
data.fill('A');
|
||||||
}
|
}
|
||||||
|
|
||||||
~NumberBase26() noexcept = default;
|
~NumberBase26() noexcept = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Cela permet d'incrémenter le nombre.
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
NumberBase26 &operator++() {
|
NumberBase26 &operator++() {
|
||||||
if (whichDigit > 0 && data[whichDigit] == 'Z')
|
std::uint32_t number{ lut.at(data.back()) + 1 }; // C'est là où se trouve l'incrémentation
|
||||||
--whichDigit;
|
/*
|
||||||
const std::uint32_t number{ lut.at(data[whichDigit]) + 1 }; // C'est là où se trouve l'incrémentation
|
* Tant que la retenue se propage à travers les digit, il faut les mettre à 'A' et
|
||||||
data[whichDigit] = number == 26 ? alphabet[0] : alphabet[number];
|
* poursuivre jusqu'à rencontrer un caractère != 'Z'
|
||||||
|
*/
|
||||||
|
for (auto iter = data.rbegin(); iter != data.rend(); ++iter) {
|
||||||
|
if (retenue) {
|
||||||
|
number = lut.at(*iter) + 1;
|
||||||
|
}
|
||||||
|
if (number == valMax) {
|
||||||
|
*iter = 'A';
|
||||||
|
retenue = true;
|
||||||
|
} else {
|
||||||
|
*iter = alphabet[number];
|
||||||
|
retenue = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +132,8 @@ struct NumberBase26 final {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::size_t whichDigit{ data.size() - 1 };
|
//! Signifie la présence d'une retenue.
|
||||||
|
bool retenue{ false };
|
||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@ -239,9 +260,8 @@ int main() {
|
|||||||
NumberBase26<maxDig> number_base_26{ alphabet };
|
NumberBase26<maxDig> number_base_26{ alphabet };
|
||||||
for (size_t i = 0; i < maxCompute; ++i, ++number_base_26) {
|
for (size_t i = 0; i < maxCompute; ++i, ++number_base_26) {
|
||||||
const auto crc = ~(getCrc32(std::string_view{ number_base_26.data.data(), maxDig }));
|
const auto crc = ~(getCrc32(std::string_view{ number_base_26.data.data(), maxDig }));
|
||||||
if (std::find(cheat_list.cbegin(), cheat_list.cend(), crc) != cheat_list.cend()) {
|
if (std::find(cheat_list.cbegin(), cheat_list.cend(), crc) != cheat_list.cend())
|
||||||
std::cout << number_base_26 << ":0x" << std::hex << crc << '\n';
|
std::cout << number_base_26 << ":0x" << std::hex << crc << '\n';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user