cc19.7: implemented.

master
Michael Hope 5 years ago
parent c84913f29d
commit d25c57d2c5
  1. 4
      CMakeLists.txt
  2. 27
      cc197.cc

@ -66,6 +66,10 @@ add_executable(cc195 cc195.cc)
target_link_libraries(cc195 ${CONAN_LIBS})
add_test(cc195 bin/cc195)
add_executable(cc197 cc197.cc)
target_link_libraries(cc197 ${CONAN_LIBS})
add_test(cc197 bin/cc197)
add_executable(cx_shuffle cx_shuffle.cc)
target_link_libraries(cx_shuffle ${CONAN_LIBS})
add_test(cx_shuffle bin/cx_shuffle)

@ -0,0 +1,27 @@
// Return the score for a mastermind guess.
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
#include <range/v3/all.hpp>
using namespace ranges;
template<typename T>
static T max_seq(std::initializer_list<T> seq) {
std::vector<T> items{seq};
T top = items[0];
for (auto start : view::ints(0ul, items.size())) {
for (auto stop : view::ints(start + 1, items.size())) {
auto sum = accumulate(items | view::slice(start, stop), 0);
top = std::max(sum, top);
}
}
return top;
}
TEST_CASE("cc19.9", "max_seq") {
CHECK(max_seq({2, -8, 3, -2, 4, -10}) == 5);
}
Loading…
Cancel
Save