Advent of Code 2022 day 4
This commit is contained in:
parent
104f034568
commit
fda6088f7c
2 changed files with 1042 additions and 0 deletions
1000
advent_of_code_2022/day4/input.txt
Normal file
1000
advent_of_code_2022/day4/input.txt
Normal file
File diff suppressed because it is too large
Load diff
42
advent_of_code_2022/day4/main.cc
Normal file
42
advent_of_code_2022/day4/main.cc
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
struct Range
|
||||||
|
{
|
||||||
|
int start{};
|
||||||
|
int end{};
|
||||||
|
};
|
||||||
|
|
||||||
|
Range read()
|
||||||
|
{
|
||||||
|
Range range;
|
||||||
|
std::cin >> range.start;
|
||||||
|
std::cin.ignore(1);
|
||||||
|
std::cin >> range.end;
|
||||||
|
return range;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int full_overlaps = 0;
|
||||||
|
int partial_overlaps = 0;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Range r1 = read();
|
||||||
|
std::cin.ignore(1);
|
||||||
|
Range r2 = read();
|
||||||
|
|
||||||
|
if ((r1.start <= r2.start && r1.end >= r2.end) || (r1.start >= r2.start && r1.end <= r2.end))
|
||||||
|
++full_overlaps;
|
||||||
|
|
||||||
|
if ((r1.start <= r2.start && r1.end >= r2.start) || (r1.start <= r2.end && r1.end >= r2.start))
|
||||||
|
++partial_overlaps;
|
||||||
|
|
||||||
|
if (std::cin.eof())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt::print(" Full Overlaps: {}\n", full_overlaps);
|
||||||
|
fmt::print("Partial Overlaps: {}\n", partial_overlaps);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue