Browse Source

feat: python script for short code verify

master
Dnomd343 2 years ago
parent
commit
e83d1dce4e
  1. 65
      klotski/main.cc
  2. 33
      verify.py

65
klotski/main.cc

@ -30,47 +30,48 @@ int main(int argc, char *argv[]) {
// printf("%09lX\n", s.unzip_short_code(14323231));
uint32_t start_code = atoi(argv[1]);
uint32_t end_code = atoi(argv[2]);
// std::cout << "preparing..." << std::endl;
// std::vector<uint64_t> all_cases;
// auto a = AllCases(AllCases::ALL_CASES);
// for (int head = 0; head < 16; ++head) {
// uint64_t prefix = (uint64_t)head << 32;
// for (const auto &range : (*a.get_all_cases())[head]) {
// all_cases.emplace_back(prefix | range);
// }
// }
//
//// auto s = ShortCode(ShortCode::Mode::NORMAL);
std::vector<uint64_t> all_cases;
auto a = AllCases(AllCases::ALL_CASES);
for (int head = 0; head < 16; ++head) {
uint64_t prefix = (uint64_t)head << 32;
for (const auto &range : (*a.get_all_cases())[head]) {
all_cases.emplace_back(prefix | range);
}
}
auto s = ShortCode(ShortCode::Mode::NORMAL);
// auto s = ShortCode(ShortCode::Mode::FAST);
// std::cout << "start working" << std::endl;
//
// for (auto short_code = 0; short_code < all_cases.size(); ++short_code) {
// uint64_t common_code = all_cases[short_code];
//
// if (short_code != s.zip_short_code(common_code)) {
// printf("ERROR: zip %d\n", short_code);
// }
// if (common_code != s.unzip_short_code(short_code)) {
// printf("ERROR: unzip %09lX\n", common_code);
// }
//
for (auto short_code = start_code; short_code < end_code + 1; ++short_code) {
uint64_t common_code = all_cases[short_code];
if (short_code != s.zip_short_code(common_code)) {
printf("ERROR: zip %d\n", short_code);
}
if (common_code != s.unzip_short_code(short_code)) {
printf("ERROR: unzip %09lX\n", common_code);
}
// if (short_code % 2000000 == 0) {
//// if (short_code % 10000 == 0) {
// if (short_code % 10000 == 0) {
// std::cout << ((float)short_code / (float)all_cases.size() * 100) << "%" << std::endl;
// }
// }
}
// std::cout << "complete verify" << std::endl;
std::cout << "[" << start_code << ", " << end_code << "]," << std::endl;
// 0 ~ 29334497
uint32_t start_code = atoi(argv[1]);
uint32_t end_code = atoi(argv[2]);
for (uint32_t short_code = start_code; short_code < end_code + 1; ++short_code) {
if (short_code != ShortCode::code_from_string(ShortCode::code_to_string(short_code))) {
std::cout << "ERROR: " << short_code << std::endl;
}
}
// for (uint32_t short_code = 0; short_code < 29334498; ++short_code) {
// if (short_code != ShortCode::code_from_string(ShortCode::code_to_string(short_code))) {
// std::cout << "ERROR: " << short_code << std::endl;
// }
// }
// std::cout << ShortCode::code_to_string(14323231) << std::endl;
// std::cout << ShortCode::code_from_string("EP4HZ") << std::endl;

33
verify.py

@ -0,0 +1,33 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import subprocess
process_list = []
CASE_NUMBER = 29334
# CASE_NUMBER = 29334498
thread_num = int(sys.argv[1])
sub_length = ((CASE_NUMBER - 1) // thread_num) + 1
def run_check(start_code: int, end_code: int) -> None:
print('[%d, %d] -> %d' % (start_code, end_code, end_code - start_code + 1))
process_list.append(
subprocess.Popen(['./klotski', str(start_code), str(end_code)])
)
start = 0
for i in range(0, thread_num):
if i + 1 == thread_num:
end = CASE_NUMBER - 1
else:
end = start + sub_length - 1
run_check(start, end)
start += sub_length
print('-' * 64)
for process in process_list:
process.wait()
Loading…
Cancel
Save