This commit is contained in:
Hugo Mårdbrink 2023-12-01 13:46:02 +01:00
commit 4ea258eb1f
6 changed files with 1111 additions and 0 deletions

28
.clang-tidy Normal file
View file

@ -0,0 +1,28 @@
Checks: "-*,clang-analyzer-*"
ColumnLimit: 120
HeaderFilterRegex: ".*"
FormatStyle: file
DeriveLineEnding: false
IndentWidth: 2
TabWidth: 2
UseTab: Always
SpacesBeforeTrailingComments: 1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesInAngles: false
BreakBeforeBraces: Allman
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
AfterLambda: true

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/build
/.vscode

19
CMakeLists.txt Normal file
View file

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.21)
project(aoc23 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(executables d1)
foreach(executable ${executables})
add_executable(${executable} "${executable}/main.cxx")
endforeach()
set(CMAKE_CXX_CLANG_TIDY
clang-tidy;
-checks=*;
-header-filter=.*;
)

10
README.md Normal file
View file

@ -0,0 +1,10 @@
# AOC23
In c++
```bash
mkdir build
cd build
cmake ..
make
```

1000
d1/input.txt Normal file

File diff suppressed because it is too large Load diff

52
d1/main.cxx Normal file
View file

@ -0,0 +1,52 @@
#include <numeric>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
int main()
{
std::ifstream file{"../d1/input.txt"};
std::string line, value;
std::vector<int> numbers;
std::unordered_map<std::string, char> letterMap{{"one", '1'},
{"two", '2'},
{"three", '3'},
{"four", '4'},
{"five", '5'},
{"six", '6'},
{"seven", '7'},
{"eight", '8'},
{"nine", '9'}};
while (std::getline(file, line))
{
std::map<int, char> lineNumbers;
for (const auto &entry : letterMap)
{
auto pos = line.find(entry.first);
while (pos != std::string::npos)
{
lineNumbers[pos] = entry.second;
pos = line.find(entry.first, pos + 1);
}
}
auto fstItr = std::find_if(line.begin(), line.end(), [](char c)
{ return isdigit(c); });
auto sndItr = std::find_if(line.rbegin(), line.rend(), [](char c)
{ return isdigit(c); });
if (fstItr != line.end())
{
lineNumbers[std::distance(line.begin(), fstItr)] = *fstItr;
lineNumbers[std::distance(line.rbegin(), sndItr)] = *sndItr;
}
numbers.emplace_back(std::stoi(std::string(1, lineNumbers.begin()->second) + lineNumbers.rbegin()->second));
}
std::cout << std::accumulate(numbers.begin(), numbers.end(), 0) << std::endl;
return 0;
}