Add 2021 Day 1 solutions

This commit is contained in:
2022-11-27 17:22:43 +00:00
parent 931ad402fa
commit df9078ff37
2 changed files with 56 additions and 0 deletions

21
2018/puzzle-01-01.cc Normal file
View File

@@ -0,0 +1,21 @@
//
// Created by Matthew Gretton-Dann on 01/12/2021.
//
#include <cstdlib>
#include <iostream>
#include <string>
using Int = std::int64_t;
auto main() -> int
{
Int value{0};
std::string line;
while (std::getline(std::cin, line)) {
Int incr{std::stoll(line)};
value += incr;
}
std::cout << "Frequency: " << value << '\n';
return EXIT_SUCCESS;
}

35
2018/puzzle-01-02.cc Normal file
View File

@@ -0,0 +1,35 @@
//
// Created by Matthew Gretton-Dann on 01/12/2021.
//
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using Int = std::int64_t;
auto main() -> int
{
Int value{0};
std::string line;
std::set<Int> freqs;
std::vector<Int> input;
freqs.insert(0);
while (std::getline(std::cin, line)) {
input.emplace_back(std::stoll(line));
}
while (true) {
for (auto incr : input) {
value += incr;
auto [it, success] = freqs.insert(value);
if (!success) {
std::cout << "Double frequency seen at: " << value << '\n';
return 0;
}
}
}
}