Add .clang-format and apply it

This commit is contained in:
2021-12-02 07:18:16 +00:00
parent e58dede1b6
commit cd5e2538df
103 changed files with 2714 additions and 2132 deletions

View File

@@ -3,21 +3,22 @@
//
#include <cstdlib>
#include <iostream>
#include <limits>
#include <string>
#include <iostream>
int main(void) {
unsigned long prev{std::numeric_limits<unsigned long>::max()};
unsigned incrs{0};
std::string line;
while (std::getline(std::cin, line)) {
auto current{std::stoul(line)};
if (current > prev) {
++incrs;
}
prev = current;
int main(void)
{
unsigned long prev{std::numeric_limits<unsigned long>::max()};
unsigned incrs{0};
std::string line;
while (std::getline(std::cin, line)) {
auto current{std::stoul(line)};
if (current > prev) {
++incrs;
}
std::cout << "Number of increments: " << incrs << '\n';
return EXIT_SUCCESS;
prev = current;
}
std::cout << "Number of increments: " << incrs << '\n';
return EXIT_SUCCESS;
}

View File

@@ -3,30 +3,31 @@
//
#include <cstdlib>
#include <iostream>
#include <limits>
#include <string>
#include <iostream>
#include <vector>
int main(void) {
std::vector<unsigned long> nums;
unsigned incrs{0};
std::string line;
while (std::getline(std::cin, line)) {
nums.push_back(std::stoul(line));
int main(void)
{
std::vector<unsigned long> nums;
unsigned incrs{0};
std::string line;
while (std::getline(std::cin, line)) {
nums.push_back(std::stoul(line));
}
assert(nums.size() >= 3);
unsigned long prev{std::numeric_limits<unsigned long>::max()};
for (std::size_t pos = 0; pos <= nums.size() - 3; ++pos) {
unsigned long current{0};
for (std::size_t i = pos + 0; i < pos + 3; ++i) {
current += nums[i];
}
assert(nums.size() >= 3);
unsigned long prev{std::numeric_limits<unsigned long>::max()};
for (std::size_t pos = 0; pos <= nums.size() - 3; ++pos) {
unsigned long current{0};
for (std::size_t i = pos + 0; i < pos + 3; ++i) {
current += nums[i];
}
if (current > prev) {
++incrs;
}
prev = current;
if (current > prev) {
++incrs;
}
std::cout << "Number of increments: " << incrs << '\n';
return EXIT_SUCCESS;
prev = current;
}
std::cout << "Number of increments: " << incrs << '\n';
return EXIT_SUCCESS;
}

View File

@@ -2,31 +2,31 @@
// Created by Matthew Gretton-Dann on 02/12/2021.
//
#include <string>
#include <iostream>
#include <string>
int main()
{
using namespace std::string_literals;
using namespace std::string_literals;
static const auto fwd{"forward "s};
static const auto down{"down "s};
static const auto up{"up "s};
static const auto fwd{"forward "s};
static const auto down{"down "s};
static const auto up{"up "s};
std::string line;
unsigned long horiz{0};
unsigned long depth{0};
while (std::getline(std::cin, line)) {
if (line.size() > fwd.size() && line.substr(0,fwd.size()) == fwd) {
horiz += std::stoul(line.substr(fwd.size()));
}
if (line.size() > down.size() && line.substr(0,down.size()) == down) {
depth += std::stoul(line.substr(down.size()));
}
if (line.size() > up.size() && line.substr(0,up.size()) == up) {
depth -= std::stoul(line.substr(up.size()));
}
std::string line;
unsigned long horiz{0};
unsigned long depth{0};
while (std::getline(std::cin, line)) {
if (line.size() > fwd.size() && line.substr(0, fwd.size()) == fwd) {
horiz += std::stoul(line.substr(fwd.size()));
}
if (line.size() > down.size() && line.substr(0, down.size()) == down) {
depth += std::stoul(line.substr(down.size()));
}
if (line.size() > up.size() && line.substr(0, up.size()) == up) {
depth -= std::stoul(line.substr(up.size()));
}
}
std::cout << "Distance * depth: " << horiz << " * " << depth << " = " << horiz * depth << '\n';
std::cout << "Distance * depth: " << horiz << " * " << depth << " = " << horiz * depth << '\n';
}

View File

@@ -2,34 +2,34 @@
// Created by Matthew Gretton-Dann on 02/12/2021.
//
#include <string>
#include <iostream>
#include <string>
int main()
{
using namespace std::string_literals;
using namespace std::string_literals;
static const auto fwd{"forward "s};
static const auto down{"down "s};
static const auto up{"up "s};
static const auto fwd{"forward "s};
static const auto down{"down "s};
static const auto up{"up "s};
std::string line;
unsigned long horiz{0};
unsigned long depth{0};
unsigned long aim{0};
while (std::getline(std::cin, line)) {
if (line.size() > fwd.size() && line.substr(0,fwd.size()) == fwd) {
auto dist{std::stoul(line.substr(fwd.size()))};
horiz += dist;
depth += aim * dist;
}
if (line.size() > down.size() && line.substr(0,down.size()) == down) {
aim += std::stoul(line.substr(down.size()));
}
if (line.size() > up.size() && line.substr(0,up.size()) == up) {
aim -= std::stoul(line.substr(up.size()));
}
std::string line;
unsigned long horiz{0};
unsigned long depth{0};
unsigned long aim{0};
while (std::getline(std::cin, line)) {
if (line.size() > fwd.size() && line.substr(0, fwd.size()) == fwd) {
auto dist{std::stoul(line.substr(fwd.size()))};
horiz += dist;
depth += aim * dist;
}
if (line.size() > down.size() && line.substr(0, down.size()) == down) {
aim += std::stoul(line.substr(down.size()));
}
if (line.size() > up.size() && line.substr(0, up.size()) == up) {
aim -= std::stoul(line.substr(up.size()));
}
}
std::cout << "Distance * depth: " << horiz << " * " << depth << " = " << horiz * depth << '\n';
std::cout << "Distance * depth: " << horiz << " * " << depth << " = " << horiz * depth << '\n';
}