refactor utils
This commit is contained in:
21
day3.cpp
21
day3.cpp
@@ -4,9 +4,8 @@
|
||||
|
||||
#include <ranges>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include "doctest.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace day3 {
|
||||
const std::string sample = "987654321111111\n"
|
||||
@@ -16,12 +15,8 @@ const std::string sample = "987654321111111\n"
|
||||
|
||||
auto split_into_banks(const std::string_view input) {
|
||||
return std::views::split(input, '\n')
|
||||
| std::views::filter([](const auto &s) {
|
||||
return !s.empty();
|
||||
})
|
||||
| std::views::transform([](const auto &x) {
|
||||
return std::string_view(x);
|
||||
});
|
||||
| std::views::transform(utils::to_string_view)
|
||||
| std::views::filter(utils::non_empty);
|
||||
}
|
||||
|
||||
uint64_t solve(const std::string_view input, uint8_t num_batteries) {
|
||||
@@ -58,10 +53,7 @@ TEST_CASE("solve first sample") {
|
||||
}
|
||||
|
||||
TEST_CASE("solve first puzzle") {
|
||||
std::ifstream input("day3input.txt");
|
||||
std::stringstream buf;
|
||||
buf << input.rdbuf();
|
||||
CHECK(solve(buf.view(),2) == 17095);
|
||||
CHECK(solve(utils::read_file("day3input.txt"),2) == 17095);
|
||||
}
|
||||
|
||||
TEST_CASE("solve second sample") {
|
||||
@@ -69,10 +61,7 @@ TEST_CASE("solve second sample") {
|
||||
}
|
||||
|
||||
TEST_CASE("solve second input") {
|
||||
std::ifstream input("day3input.txt");
|
||||
std::stringstream buf;
|
||||
buf << input.rdbuf();
|
||||
CHECK(solve(buf.view(), 12) == 168794698570517);
|
||||
CHECK(solve(utils::read_file("day3input.txt"), 12) == 168794698570517);
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
||||
Reference in New Issue
Block a user