From e156940eada7bd494849348e3449fa92ae170a59 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 6 Jan 2023 19:58:23 +0800 Subject: [PATCH] remove: legacy code --- all_cases/CMakeLists.txt | 4 --- all_cases/short_code.cc | 55 ---------------------------------------- all_cases/short_code.h | 10 -------- 3 files changed, 69 deletions(-) delete mode 100644 all_cases/CMakeLists.txt delete mode 100644 all_cases/short_code.cc delete mode 100644 all_cases/short_code.h diff --git a/all_cases/CMakeLists.txt b/all_cases/CMakeLists.txt deleted file mode 100644 index a8d7f70..0000000 --- a/all_cases/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -set(CMAKE_CXX_STANDARD 14) - -add_executable(klotski short_code.cc) diff --git a/all_cases/short_code.cc b/all_cases/short_code.cc deleted file mode 100644 index 2d779c8..0000000 --- a/all_cases/short_code.cc +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include -#include "short_code.h" - -// TODO: try to remove: `0` `O` `I` `l` - -const uint32_t ALL_CASES_NUMBER = 29334498; - -std::string code_to_string(uint32_t short_code) { - if (short_code >= ALL_CASES_NUMBER) { - throw std::range_error("short code out of range"); - } - std::string result(5, '\0'); // short code length 5 - for (int i = 0; i < 5; ++i) { - uint8_t bit = short_code % 36; - short_code = (short_code - bit) / 36; - if (bit < 10) { - result[4 - i] = char(bit + 48); // 0 ~ 9 - } else { - result[4 - i] = char(bit + 55); // A ~ Z - } - } - return result; -} - -uint32_t code_from_string(const std::string &short_code) { - if (short_code.length() != 5) { - throw std::runtime_error("invalid short code"); - } - uint32_t result = 0; - for (auto &bit : short_code) { - result *= 36; - if (bit >= '0' && bit <= '9') { - result += bit - 48; // 0 ~ 9 - } else if (bit >= 'A' && bit <= 'Z') { - result += bit - 55; // A ~ Z - } else if (bit >= 'a' && bit <= 'z') { - result += bit - 87; // a ~ z - } else { - throw std::runtime_error("invalid short code"); - } - } - if (result >= ALL_CASES_NUMBER) { - throw std::range_error("short code out of range"); - } - return result; -} - -int main() { - -// std::cout << code_to_string(14323231) << std::endl; -// std::cout << code_from_string("8IzVj") << std::endl; - - return 0; -} diff --git a/all_cases/short_code.h b/all_cases/short_code.h deleted file mode 100644 index 2e8e473..0000000 --- a/all_cases/short_code.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include - -class ShortCode { -public: - uint32_t zip_short_code(uint64_t code); - uint64_t unzip_short_code(uint32_t short_code); - -};