Totalement fonctionnel et opti + scalable.

master
Pcornat 2 years ago
parent 296f78b404
commit aadc82a004
No known key found for this signature in database
GPG Key ID: 873C3ACCF970C74E
  1. 215
      main.cpp

@ -1,18 +1,17 @@
#include <iostream>
#include <array>
#include <vector>
#include <boost/crc.hpp>
#include <omp.h>
#include <frozen/unordered_map.h>
/**
* \brief
* \param my_string
* \param myString
* \return
*/
boost::crc_32_type::value_type getCrc32(const char *__restrict__ const my_string, const std::size_t size) {
boost::crc_32_type::value_type getCrc32(const char *__restrict__ const myString, const std::size_t size) {
boost::crc_32_type result;
result.process_bytes(my_string, size);
result.process_bytes(myString, size);
return result.checksum();
}
@ -24,23 +23,23 @@ boost::crc_32_type::value_type getCrc32(const char *__restrict__ const my_string
*/
template<typename T>
constexpr std::size_t maxDigits(T n) {
std::size_t numDigit = 1;
std::size_t num_digit = 1;
while (n != 0) {
n /= 26;
++numDigit;
++num_digit;
}
return numDigit;
return num_digit;
}
template<std::size_t ArraySize>
struct NumberBase26 final {
std::array<char, ArraySize> data{};
static constexpr std::uint32_t valMax{ 26 };
static constexpr std::uint32_t val_max{ 26 };
const std::array<char, valMax> &alphabet{};
const std::array<char, val_max> &alphabet{};
static constexpr frozen::unordered_map<char, std::uint32_t, valMax> lut = {
[[maybe_unused]] static constexpr frozen::unordered_map<char, std::uint32_t, val_max> lut = {
{ 'A', 0 },
{ 'B', 1 },
{ 'C', 2 },
@ -71,7 +70,7 @@ struct NumberBase26 final {
NumberBase26() = delete;
explicit NumberBase26(const std::array<char, valMax> &_alphabet) : alphabet(_alphabet) {
explicit NumberBase26(const std::array<char, val_max> &alphabet) : alphabet(alphabet) {
data.fill('A');
}
@ -81,13 +80,13 @@ struct NumberBase26 final {
for (size_t i = data.size() - 1; 0 <= i; --i) {
if (n == 0)
return;
data[i] = alphabet[n % valMax];
n /= valMax;
data[i] = alphabet[n % val_max];
n /= val_max;
}
}
friend std::ostream &operator<<(std::ostream &os, const NumberBase26 &number_base_26) {
std::for_each(number_base_26.data.cbegin(), number_base_26.data.cend(), [&](const auto &number) -> void { os << number; });
friend std::ostream &operator<<(std::ostream &os, const NumberBase26 &numberBase26) {
(void) std::for_each(numberBase26.data.cbegin(), numberBase26.data.cend(), [&](const auto &number) -> void { os << number; });
return os;
}
@ -96,93 +95,94 @@ struct NumberBase26 final {
int main() {
// I love deduction guides :D
constexpr std::array cheat_list{
0xDE4B237Du,
0xB22A28D1u,
0x5A783FAEu,
0xEECCEA2Bu,
0x42AF1E28u,
0x555FC201u,
0x2A845345u,
0xE1EF01EAu,
0x771B83FCu,
0x5BF12848u,
0x44453A17u,
0xFCFF1D08u,
0xB69E8532u,
0x8B828076u,
0xDD6ED9E9u,
0xA290FD8Cu,
0x3484B5A7u,
0x43DB914Eu,
0xDBC0DD65u,
0xD08A30FEu,
0x37BF1B4Eu,
0xB5D40866u,
0xE63B0D99u,
0x675B8945u,
0x4987D5EEu,
0x2E8F84E8u,
0x1A9AA3D6u,
0xE842F3BCu,
0x0D5C6A4Eu,
0x74D4FCB1u,
0xB01D13B8u,
0x66516EBCu,
0x4B137E45u,
0x78520E33u,
0x3A577325u,
0xD4966D59u,
0x5FD1B49Du,
0xA7613F99u,
0x1792D871u,
0xCBC579DFu,
0x4FEDCCFFu,
0x44B34866u,
0x2EF877DBu,
0x2781E797u,
0x2BC1A045u,
0xB2AFE368u,
0xFA8DD45Bu,
0x8DED75BDu,
0x1A5526BCu,
0xA48A770Bu,
0xB07D3B32u,
0x80C1E54Bu,
0x5DAD0087u,
0x7F80B950u,
0x6C0FA650u,
0xF46F2FA4u,
0x70164385u,
0x885D0B50u,
0x151BDCB3u,
0xADFA640Au,
0xE57F96CEu,
0x040CF761u,
0xE1B33EB9u,
0xFEDA77F7u,
0x8CA870DDu,
0x9A629401u,
0xF53EF5A5u,
0xF2AA0C1Du,
0xF36345A8u,
0x8990D5E1u,
0xB7013B1Bu,
0xCAEC94EEu,
0x31F0C3CCu,
0xB3B3E72Au,
0xC25CDBFFu,
0xD5CF4EFFu,
0x680416B1u,
0xCF5FDA18u,
0xF01286E9u,
0xA841CC0Au,
0x31EA09CFu,
0xE958788Au,
0x02C83A7Cu,
0xE49C3ED4u,
0x171BA8CCu,
0x86988DAEu,
0x2BDD2FA1u };
0xDE4B237DU,
0xB22A28D1U,
0x5A783FAEU,
0xEECCEA2BU,
0x42AF1E28U,
0x555FC201U,
0x2A845345U,
0xE1EF01EAU,
0x771B83FCU,
0x5BF12848U,
0x44453A17U,
0xFCFF1D08U,
0xB69E8532U,
0x8B828076U,
0xDD6ED9E9U,
0xA290FD8CU,
0x3484B5A7U,
0x43DB914EU,
0xDBC0DD65U,
0xD08A30FEU,
0x37BF1B4EU,
0xB5D40866U,
0xE63B0D99U,
0x675B8945U,
0x4987D5EEU,
0x2E8F84E8U,
0x1A9AA3D6U,
0xE842F3BCU,
0x0D5C6A4EU,
0x74D4FCB1U,
0xB01D13B8U,
0x66516EBCU,
0x4B137E45U,
0x78520E33U,
0x3A577325U,
0xD4966D59U,
0x5FD1B49DU,
0xA7613F99U,
0x1792D871U,
0xCBC579DFU,
0x4FEDCCFFU,
0x44B34866U,
0x2EF877DBU,
0x2781E797U,
0x2BC1A045U,
0xB2AFE368U,
0xFA8DD45BU,
0x8DED75BDU,
0x1A5526BCU,
0xA48A770BU,
0xB07D3B32U,
0x80C1E54BU,
0x5DAD0087U,
0x7F80B950U,
0x6C0FA650U,
0xF46F2FA4U,
0x70164385U,
0x885D0B50U,
0x151BDCB3U,
0xADFA640AU,
0xE57F96CEU,
0x040CF761U,
0xE1B33EB9U,
0xFEDA77F7U,
0x8CA870DDU,
0x9A629401U,
0xF53EF5A5U,
0xF2AA0C1DU,
0xF36345A8U,
0x8990D5E1U,
0xB7013B1BU,
0xCAEC94EEU,
0x31F0C3CCU,
0xB3B3E72AU,
0xC25CDBFFU,
0xD5CF4EFFU,
0x680416B1U,
0xCF5FDA18U,
0xF01286E9U,
0xA841CC0AU,
0x31EA09CFU,
0xE958788AU,
0x02C83A7CU,
0xE49C3ED4U,
0x171BA8CCU,
0x86988DAEU,
0x2BDD2FA1U };
constexpr std::array alphabet{
'A',
'B',
@ -210,14 +210,15 @@ int main() {
'X',
'Y',
'Z' }; // taille = 26
constexpr std::size_t maxCompute = 308915776;
constexpr std::size_t maxDig = maxDigits(maxCompute);
NumberBase26<maxDig> number_base_26{ alphabet };
constexpr std::size_t max_compute = 308915776;
constexpr std::size_t max_dig = maxDigits(max_compute);
NumberBase26<max_dig> number_base_26{ alphabet };
const double start = omp_get_wtime();
#pragma omp parallel for firstprivate(number_base_26)
for (size_t i = 0; i < maxCompute; ++i) {
#pragma omp parallel for firstprivate(number_base_26) schedule(guided)
for (size_t i = 0; i < max_compute; ++i) {
number_base_26(i);
const auto crc = ~(getCrc32(number_base_26.data.data(), number_base_26.data.size()));
if (std::find(cheat_list.cbegin(), cheat_list.cend(), crc) != cheat_list.cend()) {

Loading…
Cancel
Save