From 58f3ebc598414a5d64f0471f6fbc9aff32900cb5 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Wed, 18 Jan 2023 19:14:20 +0800 Subject: [PATCH] feat: get step number with latest code --- src/fast_cal/fast_cal.cc | 14 ++++++++++++++ src/fast_cal/fast_cal.h | 2 ++ src/main.cc | 10 ++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/fast_cal/fast_cal.cc b/src/fast_cal/fast_cal.cc index 6a01d04..bee5e8b 100644 --- a/src/fast_cal/fast_cal.cc +++ b/src/fast_cal/fast_cal.cc @@ -185,6 +185,20 @@ std::vector FastCal::furthest(uint64_t code) { } +uint32_t FastCal::step_num(uint64_t code) { + + uint32_t num = 0; + + // TODO: confirm code exist + auto node = &cases[code]; + + while ((node = node->last) != nullptr) { + ++num; + } + + return num; +} + diff --git a/src/fast_cal/fast_cal.h b/src/fast_cal/fast_cal.h index 2f2a027..302694c 100644 --- a/src/fast_cal/fast_cal.h +++ b/src/fast_cal/fast_cal.h @@ -39,6 +39,8 @@ public: std::vector backtrack(uint64_t code); + uint32_t step_num(uint64_t code); + // TODO: static search functions diff --git a/src/main.cc b/src/main.cc index 08f4b81..948c28d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -27,14 +27,16 @@ int main() { auto f = FastCal(); // auto ret = f.solve((uint64_t)RawCode::from_common_code("1a9bf0c")); - auto ret = f.furthest((uint64_t)RawCode::from_common_code("1a9bf0c")); + auto ret = f.solve((uint64_t)RawCode::from_common_code("1a9bf0c")); + + std::cout << f.step_num(ret) << std::endl; // auto f = FastCal(RawCode::from_common_code("1a9bf0c").unwrap()); // auto ret = f.solve(); // std::cout << RawCode(ret) << std::endl; - for (const auto &r : ret) { - std::cout << RawCode(r) << std::endl; - } +// for (const auto &r : ret) { +// std::cout << RawCode(r) << std::endl; +// } // for (const auto &c : ret) { // std::cout << RawCode(c) << std::endl;