2021 - Day 1
This commit is contained in:
commit
4410cef1c4
2000
2021/1/1/input
Normal file
2000
2021/1/1/input
Normal file
File diff suppressed because it is too large
Load Diff
23
2021/1/1/main.cpp
Normal file
23
2021/1/1/main.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::fstream input("1/input", std::ios::in);
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
std::getline(input, line);
|
||||||
|
int prev = std::stoi(line);
|
||||||
|
|
||||||
|
int increases = 0;
|
||||||
|
while (std::getline(input, line)) {
|
||||||
|
int next = std::stoi(line);
|
||||||
|
|
||||||
|
if (next > prev) {
|
||||||
|
increases++;
|
||||||
|
}
|
||||||
|
|
||||||
|
prev = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Increases: " << increases << '\n';
|
||||||
|
}
|
2000
2021/1/2/input
Normal file
2000
2021/1/2/input
Normal file
File diff suppressed because it is too large
Load Diff
29
2021/1/2/main.cpp
Normal file
29
2021/1/2/main.cpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::fstream input("2/input", std::ios::in);
|
||||||
|
|
||||||
|
std::array<int, 3> a;
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
int prev = 0;
|
||||||
|
int increases = 0;
|
||||||
|
for (int i = 0; std::getline(input, line); ++i) {
|
||||||
|
std::array<int, 3> temp = a;
|
||||||
|
a[0] = std::stoi(line);
|
||||||
|
a[1] = temp[0];
|
||||||
|
a[2] = temp[1];
|
||||||
|
|
||||||
|
int sum = a[0] + a[1] + a[2];
|
||||||
|
|
||||||
|
if (i >= 3 && sum > prev) {
|
||||||
|
increases++;
|
||||||
|
}
|
||||||
|
|
||||||
|
prev = sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Increases: " << increases << '\n';
|
||||||
|
}
|
4
2021/1/build.sh
Executable file
4
2021/1/build.sh
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/bash
|
||||||
|
mkdir -p build
|
||||||
|
g++ -Wall -Wextra -Og -g 1/main.cpp -std=c++20 -o build/challenge1
|
||||||
|
g++ -Wall -Wextra -Og -g 2/main.cpp -std=c++20 -o build/challenge2
|
BIN
2021/1/build/challenge1
Executable file
BIN
2021/1/build/challenge1
Executable file
Binary file not shown.
BIN
2021/1/build/challenge2
Executable file
BIN
2021/1/build/challenge2
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user