Gain d'1 seconde.

This commit is contained in:
Pcornat 2021-03-12 21:27:45 +01:00
parent 927bcaff9a
commit 971acfe372
No known key found for this signature in database
GPG Key ID: 873C3ACCF970C74E

View File

@ -1,6 +1,8 @@
#include <iostream>
#include <array>
#include <vector>
#include <boost/crc.hpp>
#include <omp.h>
#include <frozen/unordered_map.h>
/**
@ -85,15 +87,15 @@ struct NumberBase26 final {
* Tant que la retenue se propage à travers les digit, il faut les mettre à 'A' et
* poursuivre jusqu'à rencontrer un caractère != 'Z'
*/
for (auto iter = data.rbegin(); iter != data.rend(); ++iter) {
for (std::size_t i = data.size() - 1; 0 <= i; --i) {
if (retenue) {
number = lut.at(*iter) + 1;
number = lut.at(data[i]) + 1;
}
if (number == valMax) {
*iter = 'A';
data[i] = 'A';
retenue = true;
} else {
*iter = alphabet[number];
data[i] = alphabet[number];
retenue = false;
break;
}
@ -232,11 +234,30 @@ int main() {
constexpr std::size_t maxDig = maxDigits(maxCompute);
NumberBase26<maxDig> number_base_26{ alphabet };
std::vector<std::size_t> crcs;
std::vector<char> results;
results.reserve(maxDig * maxCompute);
crcs.reserve(maxCompute);
const double start = omp_get_wtime();
for (size_t i = 0; i < maxCompute; ++i, ++number_base_26) {
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())
std::cout << number_base_26 << ":0x" << std::hex << crc << '\n';
if (std::find(cheat_list.cbegin(), cheat_list.cend(), crc) != cheat_list.cend()) {
crcs.emplace_back(crc);
for (const char &j : number_base_26.data) {
results.emplace_back(j);
}
}
}
const double stop = omp_get_wtime();
crcs.shrink_to_fit();
results.shrink_to_fit();
for (size_t i = 0; i < crcs.size(); ++i) {
for (size_t j = 0; j < maxDig; ++j) {
std::cout << results[i * maxDig + j];
}
std::cout << " : 0x" << std::hex << crcs[i] << '\n';
}
std::cout << "Temps : " << stop - start << 's' << std::endl;
return EXIT_SUCCESS;
}