advent of code 2022 day 1
This commit is contained in:
parent
a926f747c8
commit
8db2505049
5 changed files with 2324 additions and 1 deletions
29
.clangd
Normal file
29
.clangd
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
InlayHints:
|
||||
Enabled: Yes
|
||||
ParameterNames: No
|
||||
DeducedTypes: Yes
|
||||
Designators: No
|
||||
Diagnostics:
|
||||
ClangTidy:
|
||||
Add: [bugprone-*, clang-analyzer-*, concurrency-* cppcoreguidelines-*, misc-*, modernize-*, performance-*, readability-*]
|
||||
Remove: [
|
||||
bugprone-easily-swappable-parameters,
|
||||
|
||||
cppcoreguidelines-pro-type-vararg,
|
||||
|
||||
misc-const-correctness,
|
||||
misc-no-recursion,
|
||||
misc-non-private-member-variables-in-classes,
|
||||
|
||||
modernize-loop-convert, # ranges syntax not supported by linter.
|
||||
modernize-use-auto,
|
||||
modernize-use-nodiscard,
|
||||
modernize-use-trailing-return-type,
|
||||
|
||||
readability-use-anyofallof,
|
||||
readability-braces-around-statements,
|
||||
readability-convert-member-functions-to-static,
|
||||
readability-identifier-length,
|
||||
readability-magic-numbers,
|
||||
readability-uppercase-literal-suffix
|
||||
]
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
**/a.out
|
||||
|
|
@ -1 +1,2 @@
|
|||
# puzzles
|
||||
# Solutions to puzzles
|
||||
single files are compile with `g++ -ggdb -Wall -pedantic -std=c++20 -DFMT_HEADER_ONLY`
|
||||
2250
advent_of_code_2022/day_1/input.txt
Normal file
2250
advent_of_code_2022/day_1/input.txt
Normal file
File diff suppressed because it is too large
Load diff
42
advent_of_code_2022/day_1/main.cc
Normal file
42
advent_of_code_2022/day_1/main.cc
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include <algorithm>
|
||||
#include <charconv>
|
||||
#include <fmt/format.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector<std::int64_t> elves;
|
||||
elves.push_back(0);
|
||||
|
||||
std::int64_t calories{};
|
||||
std::string buffer;
|
||||
|
||||
while (!std::cin.eof())
|
||||
{
|
||||
std::getline(std::cin, buffer);
|
||||
|
||||
if (buffer.empty())
|
||||
{
|
||||
elves.push_back(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
std::from_chars(buffer.data(), buffer.data() + buffer.size(), calories);
|
||||
elves.back() += calories;
|
||||
}
|
||||
|
||||
std::int64_t max = *std::max_element(elves.begin(), elves.end());
|
||||
fmt::print("Elf with most calories has {}\n", max);
|
||||
|
||||
std::int64_t top3{};
|
||||
for (std::size_t idx = 0; idx < 3; ++idx)
|
||||
{
|
||||
auto it = std::max_element(elves.begin(), elves.end());
|
||||
top3 += *it;
|
||||
*it = 0;
|
||||
}
|
||||
|
||||
fmt::print("Top3 elves with most calories have a combined: {}\n", top3);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue