-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split range v3 example into main and test
Signed-off-by: Konstantin Läufer <[email protected]>
- Loading branch information
Showing
3 changed files
with
38 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "rangev3-aoc2022day1.hpp" | ||
|
||
#include <iostream> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include <range/v3/view.hpp> | ||
#include <range/v3/algorithm.hpp> | ||
#include <range/v3/iterator.hpp> | ||
#include <range/v3/numeric.hpp> | ||
#include <range/v3/action.hpp> | ||
|
||
using namespace ranges; | ||
|
||
// to use, redirect stdin from data/day1input.txt | ||
int main() { | ||
// read lines into vector | ||
std::vector<int> data; | ||
copy( | ||
getlines(std::cin) | ||
| views::transform( | ||
[](auto const& s) { return s.empty() ? 0 : std::stoi(s); } | ||
), | ||
back_inserter(data) | ||
); | ||
|
||
copy(data, std::ostream_iterator<int>(std::cout, " ")); | ||
std::cout << std::endl; | ||
|
||
auto result = most_nutritious_inventories(data); | ||
|
||
std::cout << "Day 1 part 1 (max) = " << result.first << "\n"; | ||
std::cout << "Day 1 part 2 (sum) = " << result.second << "\n"; | ||
} |