forked from mirror/toddcox-faster
add walk to path
This commit is contained in:
@@ -7,10 +7,20 @@ int main() {
|
||||
auto cube = tc::group::B(3);
|
||||
auto vars = cube.solve();
|
||||
|
||||
for (size_t target = 1; target < vars.size(); target++) {
|
||||
auto &action = vars.path.get(target);
|
||||
std::cout << action.from_idx << " * " << action.gen << " = " << target << std::endl;
|
||||
auto words = vars.path.walk<std::string>(
|
||||
"",
|
||||
{"a", "b", "c"},
|
||||
[](auto a, auto b) { return a + b; }
|
||||
);
|
||||
|
||||
for (const auto &word : words) {
|
||||
std::cout << word << std::endl;
|
||||
}
|
||||
|
||||
// for (size_t target = 1; target < vars.size(); target++) {
|
||||
// auto &action = vars.path.get(target);
|
||||
// std::cout << action.from_idx << " * " << action.gen << " = " << target << std::endl;
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include<array>
|
||||
#include<vector>
|
||||
#include<string>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace tc {
|
||||
struct Action {
|
||||
@@ -25,10 +26,30 @@ namespace tc {
|
||||
|
||||
void add_row();
|
||||
|
||||
[[nodiscard]] const Action get(int to_idx) const;
|
||||
[[nodiscard]] Action get(int to_idx) const;
|
||||
|
||||
void put(int from_idx, int gen, int to_idx);
|
||||
|
||||
template<class T>
|
||||
[[nodiscard]] std::vector<T> walk(
|
||||
T start,
|
||||
std::vector<T> gen_values,
|
||||
std::function<T(const T&, const T&)> op
|
||||
) const {
|
||||
std::vector<T> res(size());
|
||||
res[0] = start;
|
||||
|
||||
for (int i = 1; i < res.size(); ++i) {
|
||||
auto action = path[i];
|
||||
const auto &from = res[action.from_idx];
|
||||
const auto &val = gen_values[action.gen];
|
||||
res[i] = op(from, val);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
[[nodiscard]] size_t size() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace tc {
|
||||
path.resize(path.size() + 1);
|
||||
}
|
||||
|
||||
const Action Path::get(int to_idx) const {
|
||||
Action Path::get(int to_idx) const {
|
||||
return path[to_idx];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user