-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
80 lines (64 loc) · 1.85 KB
/
main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Advent of Code: Day 1
// Lento Manickathan
#include <chrono>
#include <fmt/ranges.h>
#include <fstream>
#include <string>
#include <vector>
#include <utils/parser.h>
#include <utils/timer.h>
static uint32_t problem1(std::string filename)
{
// Read file
auto text = utils::Text<uint32_t>(filename);
// Number of valid depths
uint32_t answer = 0;
// Check number of increasing depths
uint32_t prev_depth = -1;
for (auto depth : text)
{
// Check if new depth is higher, then is valid
if (depth > prev_depth)
answer++;
prev_depth = depth;
}
return answer;
}
static uint32_t problem2(std::string filename)
{
// Read file
auto text = utils::Text<uint32_t>(filename);
// Answer
uint32_t answer = 0;
// Check sum
uint32_t prev_sum = -1, new_sum;
for (size_t i = 1; i < text.size() - 1; ++i)
{
new_sum = text[i - 1] + text[i] + text[i + 1];
if (new_sum > prev_sum)
answer++;
prev_sum = new_sum;
}
return answer;
}
int main()
{
auto timer = utils::Timer();
constexpr uint8_t day = 1;
// Header info
fmt::print("\n🎄 Advent of Code: Day {} 🎄\n", day);
fmt::print("---------------------------\n\n");
// Test input
uint32_t test_answer1 = problem1("test_input.txt");
fmt::print(">> [Test] Problem 1: answer = {} [{}]\n",
test_answer1,
utils::pass_or_fail<uint8_t>(test_answer1, 7));
uint32_t test_answer2 = problem2("test_input.txt");
fmt::print(">> [Test] Problem 2: answer = {} [{}]\n\n",
test_answer2,
utils::pass_or_fail<uint8_t>(test_answer2, 5));
// Problem 1
fmt::print(">> Problem 1: answer = {}\n", problem1("input.txt"));
// Problem 2
fmt::print(">> Problem 2: answer = {}\n", problem2("input.txt"));
}