From e83d1dce4e165b8c7b64ac6236ae4a74852bdac0 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 6 Jan 2023 23:05:45 +0800 Subject: [PATCH] feat: python script for short code verify --- klotski/main.cc | 65 +++++++++++++++++++++++++------------------------ verify.py | 33 +++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 32 deletions(-) create mode 100755 verify.py diff --git a/klotski/main.cc b/klotski/main.cc index 4146404..193dc57 100644 --- a/klotski/main.cc +++ b/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 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 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; diff --git a/verify.py b/verify.py new file mode 100755 index 0000000..bab04e2 --- /dev/null +++ b/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()