-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay01.cpp
64 lines (55 loc) · 1.16 KB
/
Day01.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "pch.h"
#include "aoc.h"
#define NAME Day01__Report_Repair
// https://adventofcode.com/2020/day/1
namespace
{
TEST(NAME, InputA)
{
auto input = aoc::readInputFile("Day01.txt");
int result = 0;
std::vector<int> nums;
for (std::string line; std::getline(input, line); ) {
nums.push_back(std::stoi(line));
}
for (size_t i = 0; i < nums.size(); i++)
{
for (size_t j = 0; j < nums.size(); j++)
{
if (i == j) continue;
if (nums[i] + nums[j] == 2020)
{
EXPECT_EQ(nums[i] * nums[j], 259716);
return;
}
}
}
EXPECT_FALSE(true);
}
TEST(NAME, InputB)
{
auto input = aoc::readInputFile("Day01.txt");
int result = 0;
std::vector<int> nums;
for (std::string line; std::getline(input, line); ) {
nums.push_back(std::stoi(line));
}
for (size_t i = 0; i < nums.size(); i++)
{
for (size_t j = 0; j < nums.size(); j++)
{
if (i == j) continue;
for (size_t k = 0; k < nums.size(); k++)
{
if (i == k || j == k) continue;
if (nums[i] + nums[j] + nums[k] == 2020)
{
EXPECT_EQ(nums[i] * nums[j] * nums[k], 120637440);
return;
}
}
}
}
EXPECT_FALSE(true);
}
}