six seven
This commit is contained in:
@@ -85,14 +85,19 @@ std::string solution(const std::string &S) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string generate_testcase(std::size_t length, std::vector<char> charset, std::mt19937 generator, std::uniform_int_distribution<size_t> dist){
|
std::string generate_testcase(std::size_t length, std::vector<char> charset, std::ifstream& urandom){
|
||||||
if(length==0 || charset.size()==0) return "";
|
if(length==0 || charset.size()==0) return "";
|
||||||
|
|
||||||
std::string result = {};
|
std::string result = {};
|
||||||
result.resize(length);
|
result.resize(length);
|
||||||
|
|
||||||
|
thread_local std::vector<unsigned char> buffer = std::vector<unsigned char>{};
|
||||||
|
buffer.resize(length);
|
||||||
|
|
||||||
|
urandom.read(reinterpret_cast<char*>(buffer.data()), length);
|
||||||
|
|
||||||
for (size_t i= {0}; i<length; i++) {
|
for (size_t i= {0}; i<length; i++) {
|
||||||
result.at(i)=charset.at(dist(generator));
|
result.at(i)=charset.at(buffer.at(i) % charset.size());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -113,12 +118,11 @@ int main(){
|
|||||||
spdlog::error("FS error {}", e.what());
|
spdlog::error("FS error {}", e.what());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::random_device random_device = std::random_device{};
|
std::ifstream urandom = std::ifstream{"/dev/urandom", std::ios::in | std::ios::binary};
|
||||||
std::mt19937 generator = std::mt19937{random_device()};
|
|
||||||
std::uniform_int_distribution<std::size_t> dist (0, charset.size()-1);
|
|
||||||
spdlog::info("Solution to testcase 0 is: {}", solution("67A6"));
|
spdlog::info("Solution to testcase 0 is: {}", solution("67A6"));
|
||||||
for (size_t i = 0; i < 500; i++) {
|
for (size_t i = 50; i < 100; i++) {
|
||||||
std::string input = generate_testcase(i,charset, generator, dist);
|
std::string input = generate_testcase(i,charset, urandom);
|
||||||
std::string output = solution(input);
|
std::string output = solution(input);
|
||||||
|
|
||||||
std::ofstream input_file = std::ofstream{fmt::format("{}/{}.in", folder.string(), i)};
|
std::ofstream input_file = std::ofstream{fmt::format("{}/{}.in", folder.string(), i)};
|
||||||
|
|||||||
Reference in New Issue
Block a user