diff --git a/backtracking/magic_sequence.cpp b/backtracking/magic_sequence.cpp index 573d032de..e1ad400c4 100644 --- a/backtracking/magic_sequence.cpp +++ b/backtracking/magic_sequence.cpp @@ -16,10 +16,10 @@ #include /// for std::count #include /// for assert -#include /// IO operations -#include /// std::list -#include /// std::accumulate -#include /// std::vector +#include /// for IO operations +#include /// for std::list +#include /// for std::accumulate +#include /// for std::vector /** * @namespace @@ -68,7 +68,6 @@ bool is_magic(const sequence_t& s) { * @param depth * @return true if the sub-solution is valid * @return false otherwise - * */ bool filtering(const sequence_t& s, unsigned int depth) { return std::accumulate(s.cbegin(), s.cbegin() + depth, @@ -81,7 +80,6 @@ bool filtering(const sequence_t& s, unsigned int depth) { * @param s a magic sequence * @param ret list of valid magic sequences * @param depth depth in the tree - * */ void solve(sequence_t* s, std::list* ret, unsigned int depth = 0) { if (depth == s->size()) { @@ -104,11 +102,15 @@ void solve(sequence_t* s, std::list* ret, unsigned int depth = 0) { /** * @brief tests * + * @returns void */ static void test() { + // test a valid magic sequence backtracking::magic_sequence::sequence_t s_magic = {6, 2, 1, 0, 0, 0, 1, 0, 0, 0}; assert(backtracking::magic_sequence::is_magic(s_magic)); + + // test a not valid magic sequence backtracking::magic_sequence::sequence_t s_not_magic = {5, 2, 1, 0, 0, 0, 1, 0, 0, 0}; assert(!backtracking::magic_sequence::is_magic(s_not_magic)); @@ -117,6 +119,7 @@ static void test() { int main() { test(); + // solve magic sequences of size 2 to 11 and print the solutions for (unsigned int i = 2; i < 12; i++) { std::cout << "Solution for n = " << i << std::endl; std::list r1;