Compare commits

..

10 commits

Author SHA1 Message Date
840f236c60 Add VSCode configuration files for debugging and building with CMake; refactor main.cpp to clean up includes 2025-12-04 16:24:56 +00:00
c3a8206e55 Refactor Diagram structure to use mdspan for grid representation and update related functions 2025-12-04 15:47:55 +00:00
0b2afd5993 d4p2 2025-12-04 15:36:34 +00:00
eac8571ea7 Refactor CMake and VSCode settings; add Day 4 solution
- Updated .vscode/settings.json to enhance Clangd configuration and disable IntelliSense.
- Removed obsolete Clang-Format and Clang-Tidy tasks from .vscode/tasks.json.
- Modified CMakeLists.txt to enable compile commands export and adjusted target properties for Day 4.
- Added new CMakeLists.txt and main.cpp for Day 4 solution, implementing diagram parsing and movable paper counting logic.
- Included test_input and puzzle_input files for Day 4.
- Deleted the run-clang-tidy.sh script as it is no longer needed.
2025-12-04 14:22:43 +00:00
e3098c6651 D3P2 2025-12-04 12:54:27 +00:00
1fe4ecca8a D3P1 2025-12-04 11:58:32 +00:00
a4dd7b6e5b Day2 part 2 2025-12-03 23:05:57 +00:00
5d1d878d78 Day2Part1 2025-12-03 21:28:53 +00:00
86dcbd3aaf Idiot version for dayp2 2025-12-01 22:31:59 +00:00
38eca3b747 Implement safe cracking logic and setup development environment
- Added a new `main.cpp` file with logic to parse dial rotations from a file and execute safe cracking based on the parsed data.
- Introduced a `DialRotation` struct to represent the direction and distance of dial rotations.
- Implemented `parseRotations` function to read and parse input from a specified file, returning a vector of `DialRotation` or an error message.
- Created `executeSafeCrack` function to process the dial rotations and print the current state of the dial.
- Added `.clang-format` and `.clang-tidy` configuration files for code formatting and linting.
- Set up a Dockerfile for a development container with necessary tools and dependencies.
- Configured VS Code settings and tasks for building, formatting, and running clang-tidy.
- Added a script to run clang-tidy on the source files, ensuring code quality.
2025-12-01 21:01:09 +00:00
23 changed files with 5852 additions and 4 deletions

297
.clang-format Normal file
View file

@ -0,0 +1,297 @@
---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: true
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveShortCaseStatements:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCaseArrows: false
AlignCaseColons: false
AlignConsecutiveTableGenBreakingDAGArgColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveTableGenCondOperatorColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveTableGenDefinitionColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Never
AllowShortBlocksOnASingleLine: Never
AllowShortCaseExpressionOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AllowShortNamespacesOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AttributeMacros:
- __capability
BinPackArguments: true
BinPackLongBracedList: true
BinPackParameters: BinPack
BitFieldColonSpacing: Both
BracedInitializerIndentWidth: -1
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAdjacentStringLiterals: true
BreakAfterAttributes: Leave
BreakAfterJavaFieldAnnotations: false
BreakAfterReturnType: None
BreakArrays: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Attach
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTemplateCloser: false
BreakBeforeTernaryOperators: true
BreakBinaryOperations: Never
BreakConstructorInitializers: BeforeColon
BreakFunctionDefinitionParameters: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
BreakTemplateDeclarations: MultiLine
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
EnumTrailingComma: Leave
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExportBlock: true
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
BinaryMinDigits: 0
Decimal: 0
DecimalMinDigits: 0
Hex: 0
HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: true
AtStartOfFile: true
KeepFormFeed: false
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
MainIncludeChar: Quote
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
OneLineFormatOffRegex: ''
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakBeforeMemberAccess: 150
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakScopeResolution: 500
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
PPIndentWidth: -1
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: Always
RemoveBracesLLVM: false
RemoveEmptyLinesInUnwrappedLines: false
RemoveParentheses: Leave
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SkipMacroDefinitionBody: false
SortIncludes:
Enabled: true
IgnoreCase: false
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterOperatorKeyword: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterNot: false
AfterOverloadedOperator: false
AfterPlacementOperator: true
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParens: Never
SpacesInParensOptions:
ExceptDoubleParentheses: false
InCStyleCasts: false
InConditionalStatements: false
InEmptyParentheses: false
Other: false
SpacesInSquareBrackets: false
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TableGenBreakInsideDAGArg: DontBreak
TabWidth: 8
UseTab: Never
VerilogBreakBetweenInstancePorts: true
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE
WrapNamespaceBodyWithEmptyLines: Leave
...

18
.clang-tidy Normal file
View file

@ -0,0 +1,18 @@
# We explicitly enable checks with '*' and disable noisy ones with '-'
Checks: >
-*,
bugprone-*,
modernize-*,
performance-*,
readability-*,
cppcoreguidelines-*,
misc-*,
# Disable these specifically if they are too annoying
-modernize-use-trailing-return-type,
-llvmlibc-*
# Treat warnings as errors (optional, good for strict discipline)
WarningsAsErrors: ''
# This ensures clang-tidy sees the same headers as your compiler
# It will read the compile_commands.json automatically

25
.devcontainer/Dockerfile Normal file
View file

@ -0,0 +1,25 @@
FROM xianpengshen/clang-tools:21
# Install development tools (cmake, ninja, build essentials)
USER root
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
cmake \
ninja-build \
build-essential \
libc++-dev \
libc++abi-dev \
git \
python3 \
python3-pip \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Create workspace folder (VS Code devcontainer convention)
ARG WORKSPACE_FOLDER=/workspaces/aoc25
RUN mkdir -p ${WORKSPACE_FOLDER} && chown -R root:root ${WORKSPACE_FOLDER}
WORKDIR ${WORKSPACE_FOLDER}
ENV SHELL=/bin/bash
CMD ["bash"]

View file

@ -0,0 +1,20 @@
{
"name": "aoc25-clang21",
"build": {
"dockerfile": "Dockerfile"
},
"workspaceFolder": "/workspaces/aoc25",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/aoc25,type=bind,consistency=cached",
"settings": {
"C_Cpp.default.compilerPath": "/usr/bin/clang++-21",
"C_Cpp.default.intelliSenseMode": "linux-clang-x64",
"clang-format.executable": "/usr/bin/clang-format-21"
},
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cmake-tools",
"llvm-vs-code-extensions.vscode-clangd",
"xaver.clang-format"
],
"postCreateCommand": "cmake -S . -B build || true"
}

16
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,16 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "lldb",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
// CHANGE THIS LINE:
// Point the working directory to the folder containing the executable
"cwd": "${command:cmake.launchTargetDirectory}",
"preLaunchTask": "CMake: build"
}
]
}

15
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,15 @@
{
"C_Cpp.intelliSenseEngine": "disabled",
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd",
"editor.formatOnSave": true,
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.configureOnOpen": false,
"cmake.generator": "Ninja",
"clangd.arguments": [
"--background-index",
"--compile-commands-dir=${workspaceFolder}/build",
"--header-insertion=iwyu",
"--clang-tidy",
"--completion-style=detailed"
]
}

24
.vscode/tasks.json vendored Normal file
View file

@ -0,0 +1,24 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "CMake: build",
"type": "shell",
"command": "/usr/bin/cmake",
"args": [
"--build",
"${workspaceFolder}/build",
"--config",
"Debug",
"--target",
"${command:cmake.buildTargetName}"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$gcc",
"detail": "Builds the target currently selected in the CMake status bar"
}
]
}

View file

@ -1,6 +1,41 @@
cmake_minimum_required(VERSION 3.10.0)
# Set compilers before project() to ensure they're used
set(CMAKE_C_COMPILER /usr/bin/clang-21)
set(CMAKE_CXX_COMPILER /usr/bin/clang++-21)
project(aoc25 VERSION 0.1.0 LANGUAGES C CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Helper to add AoC day targets and auto-copy any input files
function(aoc_add_day name src_dir)
# remaining args are source files
set(sources ${ARGN})
add_executable(${name} ${sources})
set_target_properties(${name} PROPERTIES CXX_STANDARD 23 CXX_STANDARD_REQUIRED ON)
target_compile_options(${name} PRIVATE -stdlib=libc++)
target_link_options(${name} PRIVATE -stdlib=libc++)
# Gather common input files in the source directory
file(GLOB INPUT_FILES
"${src_dir}/*_input"
"${src_dir}/puzzle_input"
"${src_dir}/test_input"
)
foreach(f IN LISTS INPUT_FILES)
get_filename_component(fname ${f} NAME)
add_custom_command(TARGET ${name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${f} $<TARGET_FILE_DIR:${name}>/${fname}
COMMENT "Copying ${fname} to build directory for ${name}"
)
endforeach()
endfunction()
# Per-day subprojects (example: day1)
add_subdirectory(day1)
add_subdirectory(day2)
add_subdirectory(day3)
add_subdirectory(day4)

View file

@ -1,2 +1,2 @@
add_executable(day1 main.cpp)
set_target_properties(day1 PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
# Use top-level helper to add the target and copy input files
aoc_add_day(day1 "${CMAKE_CURRENT_SOURCE_DIR}" main.cpp)

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,111 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <expected>
#include <print>
int main(int, char**){
std::cout << "Hello, from aoc25 day1!\n";
struct DialRotation {
char direction;
int distance;
};
auto parseRotations(const std::string& filename) -> std::expected<std::vector<DialRotation>, std::string> {
std::ifstream inputF {filename};
if (!inputF){
return std::unexpected{"Some file open error.\n"};
}
std::vector<DialRotation> dialRotations{};
DialRotation curDial{};
while ( inputF >> curDial.direction >> curDial.distance)
{
//std::println("{} : {}", curDial.direction, curDial.distance);
dialRotations.push_back(curDial);
}
return std::move(dialRotations);
}
constexpr int dialStart = 50;
constexpr int maxDial = 100 ;
auto executeSafeCrack(const std::vector<DialRotation>& dialRotations){
int dial {dialStart};
std::cout << "The dial starts by pointing at " << dial << "\n";
int countZero = 0;
for (const auto& curDial : dialRotations){
int fullRotations = curDial.distance / maxDial;
int modulo = curDial.distance % maxDial;
if (fullRotations > 0){
std::cout << "Big number! Passed " << "" << fullRotations << " times through 0!\n";
countZero += fullRotations;
}
if(curDial.direction == 'L'){
int prevDial = dial;
dial -= modulo;
if (dial < 0){
dial += maxDial;
if (prevDial != 0) {
std::cout << "Passed through 0 from a L rotation! Count++!\n";
countZero++;
}
}
if (dial == 0){
std::cout << "Stopped at 0! Count++!\n";
countZero++;
}
}
else{
dial += modulo;
if (dial >= maxDial){
dial -= maxDial;
countZero++;
std::cout << "Passed through 0 from a R rotation! Count++!\n";
}
}
std::println("{} : {:3}, Dial now at: {:5} cnt: {}", curDial.direction, curDial.distance, dial, countZero);
if (dial < 0){
std::cout << "Shit's fucked!\n";
break;
}
if (dial >= maxDial){
std::cout << "Shit's fucked!\n";
break;
}
}
std::print("Zeros: {}\n", countZero);
return countZero;
}
auto main(int, char**) -> int {
auto retval = parseRotations("day1_input");
std::vector<DialRotation> testCase = {
{'L', 68},
{'L', 30},
{'R', 48},
{'L', 5},
{'R', 60},
{'L', 55},
{'L', 1},
{'L', 99},
{'R', 14},
{'L', 82},
{'L', 1000},
};
if(retval) {
auto realResult = executeSafeCrack(*retval);
auto result = executeSafeCrack(testCase);
std::println("Testcase result: {}", result);
std::println("Total result: {}", realResult);
}
else{
std::print("{}\n", retval.error());
}
return 0;
}

2
day2/CMakeLists.txt Normal file
View file

@ -0,0 +1,2 @@
# Use top-level helper to add the target and copy input files
aoc_add_day(day2 "${CMAKE_CURRENT_SOURCE_DIR}" main.cpp)

153
day2/main.cpp Normal file
View file

@ -0,0 +1,153 @@
#include <iostream>
#include <fstream>
#include <string>
#include <string_view>
#include <vector>
#include <expected>
#include <print>
#include <ranges>
#include <array>
#include <map>
#include <numeric>
#include <functional>
#include <algorithm>
struct IDRange {
long leftRange;
long rightRange;
};
auto parseRanges(const std::string& filename) -> std::expected<std::vector<IDRange>, std::string> {
std::ifstream inputF {filename};
if (!inputF){
return std::unexpected{"Some file open error.\n"};
}
std::vector<IDRange> idRanges{};
std::string bigString{};
std::getline(inputF,bigString);
auto ranges = std::ranges::to<std::vector<std::string>>(std::views::split(bigString, ','));
for(const auto& range : ranges){
auto subParts = std::ranges::to<std::vector<std::string>>(std::views::split(range, '-'));
idRanges.emplace_back(std::stol(subParts[0]), std::stol(subParts[1]));
}
inputF.close();
return std::move(idRanges);
}
auto countDoubles(const std::vector<IDRange>& idRanges) {
long doubles{};
for(const auto& rng : idRanges){
//std::println("{}-{}", rng.leftRange, rng.rightRange);
for( long i = rng.leftRange; i <= rng.rightRange; i++){
auto str_version = std::to_string(i) ;
auto str_len = str_version.size();
//std::print("Checking {}. Length: {}", str_version, str_version.size());
if (str_len % 2 == 0) {
//std::print(" Divisible by two, splitting...");
std::string_view left_half = std::string_view(str_version).substr(0, str_len/2);
std::string_view right_half = std::string_view(str_version).substr(str_len/2, str_len);
//std::print("Halves: {}/{}",left_half, right_half);
if(left_half == right_half){
//std::print(" EQUAL!");
doubles += i;
}
}
//std::println();
}
}
return doubles;
}
auto calculatePossibleSplits(int length) -> std::vector<int>{
//std::println("Possible ways to split a str of length {}: ", length);
std::vector<int> returnVec{};
for(auto toCheck : std::views::iota(2, length+1)){
if(length % toCheck == 0)
{
//std::println("{}", toCheck);
returnVec.push_back(toCheck);
}
}
return std::move(returnVec);
}
std::unordered_map<int, std::vector<int>> splitMap{};
auto getPossibleSplits(int length) -> const std::vector<int>&{
if(!splitMap.contains(length)){
//std::println("Caching {}",length);
splitMap[length] = calculatePossibleSplits(length);
}
return splitMap.at(length);
}
auto countRepeats(const std::vector<IDRange>& idRanges) {
long doubles{};
for(const auto& rng : idRanges){
//std::println("{}-{}", rng.leftRange, rng.rightRange);
for( long i = rng.leftRange; i <= rng.rightRange; i++){
auto str_version = std::to_string(i) ;
auto str_len = str_version.size();
//std::print("Checking {}. Length: {} ", str_version, str_version.size());
std::vector<int> numsToCheck = getPossibleSplits(str_len);
//std::println("Possible splits: {}", numsToCheck);
for (int checkNum : numsToCheck)
{
//std::print("Splitting in {}: ", checkNum);
std::vector<std::string_view> splits(checkNum);
for(auto toCheck : std::views::iota(0, checkNum)){
auto window = str_len/checkNum;
splits[toCheck] = std::string_view(str_version).substr(toCheck*window, window);
//std::print("[{}]: {} /{} ", toCheck, splits[toCheck], window);
}
if(std::equal(splits.begin() + 1, splits.end(), splits.begin())){
//std::print(" EQUAL!");
doubles += i;
break;
}
//std::println();
}
//std::println();
}
//std::println();
}
return doubles;
}
auto main() -> int {
auto testCase = parseRanges("test_input");
if(testCase) {
auto testResult = countDoubles(*testCase);
auto testResultP2 = countRepeats(*testCase);
std::println("P1 Testcase result: {}", testResult);
std::println("P2 Testcase result: {}", testResultP2);
}
else{
std::print("{}\n", testCase.error());
}
auto realRanges = parseRanges("puzzle_input");
if(realRanges) {
//auto realResult = countDoubles(*realRanges);
auto realResultP2 = countRepeats(*realRanges);
//std::println("P1 Real result: {}", realResult);
std::println("P2 Real result: {}", realResultP2);
}
else{
std::print("{}\n", realRanges.error());
}
return 0;
}

1
day2/puzzle_input Normal file
View file

@ -0,0 +1 @@
9191906840-9191941337,7671-13230,2669677096-2669816099,2-12,229599-392092,48403409-48523311,96763-229430,1919163519-1919240770,74928-96389,638049-668065,34781-73835,736781-819688,831765539-831907263,5615884-5749554,14101091-14196519,7134383-7169141,413340-625418,849755289-849920418,7745350-7815119,16717-26267,4396832-4549887,87161544-87241541,4747436629-4747494891,335-549,867623-929630,53-77,1414-3089,940604-1043283,3444659-3500714,3629-7368,79-129,5488908-5597446,97922755-98097602,182-281,8336644992-8336729448,24-47,613-1077

1
day2/test_input Normal file
View file

@ -0,0 +1 @@
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124

2
day3/CMakeLists.txt Normal file
View file

@ -0,0 +1,2 @@
# Use top-level helper to add the target and copy input files
aoc_add_day(day3 "${CMAKE_CURRENT_SOURCE_DIR}" main.cpp)

168
day3/main.cpp Normal file
View file

@ -0,0 +1,168 @@
#include <iostream>
#include <fstream>
#include <iterator>
#include <string>
#include <string_view>
#include <vector>
#include <expected>
#include <print>
#include <ranges>
#include <array>
#include <map>
#include <numeric>
#include <functional>
#include <algorithm>
struct IDRange {
long leftRange;
long rightRange;
};
auto parseBanks(const std::string& filename) -> std::expected<std::vector<std::vector<int>>, std::string> {
std::ifstream inputF {filename};
if (!inputF){
return std::unexpected{"Some file open error.\n"};
}
std::vector<std::vector<int>> banks{};
std::string bankLine{};
while(std::getline(inputF,bankLine)){
banks.emplace_back(bankLine
| std::views::transform([](char c){ return c - '0';})
| std::ranges::to<std::vector<int>>());
}
inputF.close();
return std::move(banks);
}
auto calculateJoltage(const std::vector<int>& bank) -> long{
auto curIt = bank.begin();
auto rightIt = bank.end();
//int leftMax = 0;
auto leftBound = bank.begin();
// First find biggest number with that is not the last
while(curIt != rightIt-1){
if(*curIt > *leftBound ){
leftBound = curIt;
}
//std::println("Cur: {}, lMax: {}", *curIt, *leftBound);
curIt++;
}
int rightMax = 0;
while(leftBound != rightIt) {
rightMax = std::max(rightMax, *rightIt);
rightIt--;
}
std::println("LMax: {}, rMax: {}", *leftBound, rightMax);
return (*leftBound)*10 +rightMax;
}
auto countJoltages(const std::vector<std::vector<int>>& banks) {
long totalJoltage{};
for(const auto& bank : banks){
std::println("Bank: {}", bank);
totalJoltage += calculateJoltage(bank);
}
return totalJoltage;
}
auto calculateJoltageP2(const std::vector<int>& bank) -> long long{
const int TO_TAKE = 12;
std::vector<int> takenNumbers{};
auto curIt = bank.begin();
auto rightIt = bank.end();
auto leftBound = bank.begin();
while(takenNumbers.size() != TO_TAKE){
// First find biggest number with that is not in the last 12
while(curIt != (rightIt +1 - TO_TAKE + takenNumbers.size())){
if(*curIt > *leftBound ){
leftBound = curIt;
}
curIt++;
}
takenNumbers.push_back(*leftBound);
curIt = leftBound+1;
leftBound = curIt;
}
long long intRepr = std::ranges::fold_left(takenNumbers, 0, [](long long x, long long y) -> long long{
return (x*10) + y;
});
return intRepr;
}
auto calculateJoltageP2_Optimized(const std::vector<int>& bank) -> long long {
const int TO_TAKE = 12;
if (bank.size() < TO_TAKE) { return 0; }
long long result = 0;
auto current_start = bank.begin();
for (int i = 0; i < TO_TAKE; ++i) {
int items_needed_after_this = (TO_TAKE - 1) - i;
auto search_end = bank.end() - items_needed_after_this;
auto max_it = std::max_element(current_start, search_end);
result = (result * 10) + *max_it;
current_start = max_it + 1;
}
return result;
}
auto countJoltagesP2(const std::vector<std::vector<int>>& banks) {
long totalJoltage{};
for(const auto& bank : banks){
totalJoltage += calculateJoltageP2_Optimized(bank);
}
return totalJoltage;
}
auto main() -> int {
auto testCase = parseBanks("test_input");
if(testCase) {
//auto testResult = countJoltages(*testCase);
auto testResultP2 = countJoltagesP2(*testCase);
//std::println("P1 Testcase result: {}", testResult);
std::println("P2 Testcase result: {}", testResultP2);
}
else{
std::print("{}\n", testCase.error());
}
auto realPuzzle = parseBanks("puzzle_input");
if(realPuzzle) {
//auto realResult = countJoltages(*realPuzzle);
auto realResultP2 = countJoltagesP2(*realPuzzle);
//std::println("P1 Real result: {}", realResult);
std::println("P2 Real result: {}", realResultP2);
}
else{
std::print("{}\n", realPuzzle.error());
}
return 0;
}

200
day3/puzzle_input Normal file
View file

@ -0,0 +1,200 @@
1222222312332225132221222322223222212123112122221122321222132212122312222221212112222322211112122222
1345446423422232333442846252125241622734244225359323445433441754253232142272634482426733122226243425
4577785646656747466375765575483456466553659534557243455743516567366564563657487644966426447385374456
8222241222244832332283327241231524722223244352322232213522125242245322283224432151246355541722522324
5635743334524945473375734334333434335143733447653334825456648464763377423445683323144636458153553242
3232232312232332323212122223223233223321211222211132312332324232222232322523312323232163333222323322
2472322324223274543733231232327134352234642232134332324474422235367263242723634682312212321627217212
2322173432233122122222222213121212122322122223443222342522222222251411222236234224413232123242322223
3652868667537452366966235765333245635664416546663245643298725986543622252758383653626463865737627748
3253353434242444324342234443345354345254334442434394133446153443846544445463344442443434235445352234
5525553365254244555275437345525352655555522746447455432455324534325535325273245541464725355252535575
2214425229352326112252442232322442223322421533421422132524224245252242545214333222331524435255222223
2234124522332123154444451131323344345334231233643452432242214434344233242231242332234344421524422232
3236463384444313444333424423252643421343424424235323434132354443426454435344525454443465344534334423
4543423346942324444333211221223212242324282444324344223441284163344472232231533442334222493142444332
2252414424434323225422335355623444534443242223425454222114434323343422333232215262245342315322124145
2122646344333414322344334235233373362531215643422331422265651312416332422214424426224243324542223642
3847153424154522215342336613544333655363532363224243424235531432231232223355334226233328533731422324
4213313279221255132733337332676783336438397722223623627143243336265323866272222383326952231117437536
3232133691332323342527227744573324433247223253622233171323332113722323235353712225334322234221572332
3445335444436434327374244374433344434442444442144443444264833443473634342344644763335344533673334344
6333292325523633354384344331338332264312366653353246484744834445326665525233525441397563944365838662
1422232212232134233341212239222212422322511212211252221221221311232212122322342312122222212222232242
4545663443455345754454364437755673136355444555752453744637424434742134442237535355363587654542364464
3723323233422393333326837768263333265213832212132322233392861423235237313423222323336342333932322332
2349332626622312523226252359247213331622422325232223293333234249496222352453182422439533232324235293
3252554344223424221332333445133334222243533523322421453434312323722222434332343535223326331431344432
3224323455245243765446462354444354565156446364328331212243352324112326343383442623343643333324452114
2563171155451654324562512247376555764275624737724434776266221511514262446463627513517271167474535589
2323221323223322223334221233241223231111213213212232232222332211322222532111222323231232322222332225
7424783332616784611422874441346688443382343661511421287338824445411353727864326752163275477222364319
3354533332333324343135355544433311324132422234444325333334323542434333323236543423444343227424343334
3732574422333334533553366332367433652284326723242266162436673434447364637354732463774564353343333173
4212223242312223221423321222214221222221122222221223322432331232222222224221234124112233123122123224
3233434633732743545124537434234653353464343242543244546323364447233333572534344434245434343234545544
2225242525223643221254336142222234373343222332224343332434265232343412424722166322326213372423448325
2432322533332432732522234451432243624223143437138244633421392233224232322224425221313425321446222431
2114424325322242324512124415314222144242143241432626422134224363342352224534344271233533532423443323
3223224211211258211121421231242223222222212132732212251212221332224232244332223232225222224212212382
1423131332321213313231313222233122533323233422232242231222232333331522222332121323333322232212122213
5655554636456633545666665465556655366655654365545555366536746474736775544563574766645543646465536663
3252755647445345577525346257335542222374212663671322343546264454567666534555544522382675823433726252
3244651472243442224343562543518331333224445441454272421314953422141242425435544454532935313335535434
2342333332321232221552333333344324343334632333232535253353445333332221242352242142233322232333422342
2942122243614122123433252121292245182224241221326222442224135558253129224221315828732241442331372126
2242122222421262311324444533242264443193322114222232212321121222333224312122336224333123333222223323
2522362222253223782132236734313213411233672343453425332393384438633251253243217453314522213171123341
3322333394423945242354443527243254144453523323423533223344254426635332443365444262334236433353624145
5144363655544353445575456545535555553435557475538345539433254564335654546565526555535346264443556655
4412333212122253112332322213222234222143332423432321112245112221351222222253323232332321222333225514
3212222333233323121322222232232322322222242222321232223232232413312623341322221232223233333332222312
4655445445664456554455544425246365545456565443544665558564474465663555525545635534355556553546655464
2221222262232642433342264243612222222254241322526435265474324262242262225124422365221321532222154524
2244433336631854623226311233223251314433322432662162666122313213414532223622223323213322546422123325
4222312324252212332222243163152524432335321226244344335543522253343222457323243342432525242222421143
2223412144354332412133131421325233214154422322322223722333232512232232222264544312122352221441252941
2222221222122222231166235212214217222224221227372222222621824225245122264782122371422422335232432511
2335334342152363523314422243422312212223332322222633242654124622542232252333244421322333332323523213
3297973276668316426221924925275762549257228394533832343394336485363134743218173242447539267433384546
2222222223241824142225222211232261221341411222325331212222124932222521262222262522322322312232224244
5455444375585253144452424554354432563465462783446535754146493443556344763543324646447516433845365456
7225186565757383564548236146446656162154835755533443468783467345345528846865233738243576443545572276
2432421122244344436232458835283613273272427567343262433273623255234353365532232377243247762225352224
2244342451422331233454232333223212312311311322383442232211321323342122213323223324312322143432432224
2124143431323222541232225222831262336222224232324222152222213313222152232246222252241321243122532324
1653932264143262633447653566243653172332634272456212343345236352214843653833315745321244346234693568
4319388539655436758264786843998954433446458665333836836736414628834358479866434924575444337233445547
2332231223223122222323232132233212233212234222222452122311132241223232332343322111312251321212322222
4334224233223132312223235323241144632322423352522324241333313222232722243422222233322242332422321322
7325143833445522342253575533545239454636574276452453545428245255572262258745258255454354382256551147
4313428332343335133253313633363753222432332233333223332323723434364223323322222332332333222143433243
5221121211554122623411335422212282122231242322432225222231274222222221214622142153252554222521322221
2533453653533433392736235246324663763457254654283346375627342355332223273342643242236342734633533883
2326222212232223211151222223272253222322312222113331222122322342232242222221222321122222222222222122
3254324143436364232642544433433113754463332513334433382133427353556232328232343213563352335224252422
5532336124222222122362223222331532245222452114229322142354133451222222225222222422222226346262114222
3422333321332331222122212212122222323132213222333133332242415315232233334422222226223223122232712232
6466753623243634686665566555555556355557555746645476598476241646166355284655667645578651566452676376
2863222611313324322633232242323175743363253754241522221363826251688324435122232632233229595553333333
2631233111213234235423624117353313342321331412232236313363532122713534332222638232343323223231252147
5734565454654684242455752875976553556762545674431465458856453456455676355556642665623546935661758526
2124241122142243325226342626232322442222331225222322441223224222113141221341221222322323222244512242
3323363333335333333533333422153533332323343333133353333233355132623333243333333333323233333543434323
4545332344521233543441821132432217333232244232243441433422234235444144223344442436353342244242813642
2245923758623329723677234255242626666247532456252435328826343327323255732266648272923456765867424523
4242291532296955862224621235693222398688563224642267272435923551221826272762227694597582694864322741
4525587925524756326254523845567633246353344322646355766862772549423535466234795457673626979237357587
3524846433553444343353453444363434435434444454344343344923334445343344335673454342334443344434442233
8632541534343456944443234544136653215426833324325564653222554352446552339454613554345351352224452552
4146136335256231436411256352635624365143261533236364343154432523235115664366615642155165465254523789
3337736245234343333623443435363723345343534343634383323443536464133443524362323475553435333373454234
2243332223561223133313332632353167233512223321222222262373312353422337333224222222331224233222322332
3342542757535443656354333347363535753345534333748323566223343397533576647364333799332452333497334735
6214212222222221221722423222282233322221321322232114725542222222324222214326272222322112112122323232
4566422331332323636343525522334543323323224333366434353355255332433333323327323333533336353233313345
4934444334224443372221124142644262554522744457423252263443334244444343254241357354442425444244434244
3533348344333432323395883523342323533555649546624154416673456585151454523532567353929363642354224842
3272221132643232822215223335523322212622393333432322222322423233132324328323223322951223334322323233
2112622221212122222321221212422211222332251223332222363313122222322111321112324232722228272121113129
3232523113123332333334231322321314263322131442422331323231323235332235325362312423223322534321321132
9358556673766458329644599557567935658745257592867335543536146444655376355865957353876686234678366352
5242223355523353224244441422243464324293371233324331534321421331422266422544235333234323433212338322
4653544535233343446354247333541445343474243434444143415343444434446434444524374336434443343444554245
3235533232523263225253363754561433453672725343534134563353661342643372341354333546566443434572133646
3137934345454194326447323243223235254632424543945232242332331273362453447323238335823314153439633343
2331232412262312322342322325313227322221622222176124215422231242122332221321222252713422217762621322
3515124353432543135154424243432114341133552541554315213344351351553141444244535355115221354215426789
2222222222223121112432132623144222214132252223222312331222222222221322222211222124322222181222234332
2733222222212122218223325243113392232212227226222111241242232222212321223224322112232132222333321222
7423253663522632216327236216426125525225336622341265352432225232222342252128632248522882222244423223
5656839457566364549863875929783786563887555255788384646782785655752768663427235647423543444667545663
2244224173242422144239447473244346231442242229441244124422561238512214226319427848248254394249239222
3134324244123434411111341421211242342343321332244231123443213414121333144312141321414144241432456789
2123222222532222331122223122122232122222282222352223152332321231223233322132223233212512221222222222
3433337723687313343343341333333232233143333333333444326633324332322344333435732373333339332334344633
4734552425421133624242225432756414442452344421683389322143423264864536194533224324143235262457432334
5743642663548353363383344322233736237347332333663496653345433667377423173776724473546743337486434338
6745464734746655363746438358445664347243384434547446379696644668564594954298936645584647643645765174
5562557343335352722313258363233214252223526572225225223224641266122232332222116335672252525223512224
5324226433351356545237253335433342535112223443325322434552591322233564453223344426491342444723513325
2822323232432122331246221323232343332554293136122333138422323347433214333342132232242221233462232312
3553334326333124133333333443313223333332333321325323333333423333324131233344332433233325343333334332
3553328424442352323424221244423162245575433454736413256577364757365434564463335553523652256352344234
4333423333322333233333331436323413243123352333623334333532342324242332521353623132232333533142332332
2222235323113243332323253332263323232313333332332325333223422233223322242333123343333132222223333232
5432334223333385363332322423354481633343433663433346341253542549375343333235363317433343343345273233
1211122221212523421414252524222232212242522223222173212122222222233222251223212432122221222222232222
5555341373369287553554338535578346252454585441333387475853443447548553955539636382737338684853648324
3444423436833333536435333469436413441544344643358423523832535336444252855433235443347434334335334353
4652433245373392351734541444434543592364584448349324446637446349426369323434633725425423434523353232
1613212122723622242278212221272232412222223221222123223141422438212222321217383212222222524151328272
2322312221422422243251342312132233222332232522132292212222421416224432224454211322142523242421242213
2453552449355335353333455534312653322433129233223542244232317324523453324362443644654232245354535355
3223432424314542311234346543245354543943325442344248556333321343354834323744433333325273223323236444
3273322242922222234141213432233322333233323233223332331233321362321232132213232213221182122223213132
4321354552542622325322616522523522526222253343721322354523641942223223225346435225323225616272146222
2222132222222314211222121112121222222422412332512312212238221233253221213322222225231322322222223212
3625623123174243241432662232234224452322223242162366253323442226423214114235521213214745343323445724
2533233634253623433464437438242224623365332366323247348625873244236133936564534554336313622223133233
8878788898777877487699888978898898777977877887887878896888888878889887889848788977988888888887598668
3322373372422425244333245533554547334164541333434725333551323235552289432536533452254363344345231312
1432436353334323233332333434434434433424332432323444344144364343344333333323243543333323344433453343
3321443243342233121332332324222232332123333322232343123332343442222335114332322333333322212213223233
2532352313412243222233523334241232345232323333312424323324232228332434414314322322135333233423343333
6656264513224552455562413226315265366634632353552262256444251544424652563522513324454612351466422455
3352334352963332363533134343333333333331733354223333334623335333332333343273513443333313333335523354
7234732263333313357336744324735447533332634323323355352393353854644514337353133337532334948735433414
8448646669263527951633858664544365767593846387636872455643647447578868665723215245346326842854666246
2221322254222333253532212133222723212212241322223221222224323212222221222212121223111222231222211262
1311333211332114227262347322122123232233222342227242633244212241214232121232342233132332222333228342
2433433332444244212341442233154233443534424344443252433444434434432444323414342412342522233224444234
2332233231464331642112543243233233321333362333542212223229243331222423322623331222724383423154246213
3685536668666666766346582753666677876666572767446566666855463675556368366662476666652966456454677355
1542215351142422327152324432222223322261222322114323522354322122262433432214242222241414222323352726
3343413121222324251423224222122622143221233122324132222222421215121222412121412525311221242124252342
2431163523214342142332232422413226164322332525241262222322223244236132224241222224224214264235323172
8772463943137885373335252784576835477612752314166627355584276345334339636258711682416362866626727333
1222222221421213222122273213222222222122622122225312225221122222132122322645422222621635224223112215
3532213535352425264677454321235222442623242524167515217734513234215222242343961435525732355576335421
3223214224342353422322222841224212214234222222933232633222455122323445332223455222223342651232421224
7115343354233333232372323253132342221232232311226422321722136322525334224424223223321312222223333232
4357663662356634546546765162524356556634434553343632666244395322153624565646225555345655566333465356
2434343323323343342133252224322722324433333334422225233327143133352225134332374235484355434423321374
1222252522232132523226226225267532752122243221523212222122224321337666223242631221222122242226252622
2327332235127463626626621337227622858425364527752132212321323245321645326236343171423221625251761627
5143312422222264523313532221243252242262241221552323712434423533212231135242225373522222333252243414
2233873448923333213233237234315234232333333433353463333123337333633333332733322355224533333773372694
6342346344334456623423254555234952146436432456242565674356553445434543524446245423534532524355535842
3231222524241322342342223321233231332222634322332314231223212323232436223372353212431121252233352322
4333335332232322233333231333232333333332354364223353434331233243323223533253632332333623513123322312
2212212222223222321121322222321125232226121222222322222224221222222222322222221221222221232511212222
3122221222121222544224224252252241122232222112223323231212134233131122224112214222225212222122232422
3211356356222122215133526332233222322311255422224221241321336132223233242237246223926142867353622623
2331443223411422242214536224213122324724332231312222222234322331132333313232222232322442631342122212
2221335223943374316123324235452224332232224324331562434433253432121353332529322122244445424445254222
6573934424747346565665565666563655546652665666364255554665696265663763456632338556367633652946366667
2121122324322222212122232125111223322232124363222232311432332233211222312223313321232212213421322232
5255884695277765342363572543544553876324623533752442343727423412433746382453326451584533733454633395
3638831234162153683163343733723333358337317391373322323532733343162133633642433523433237486722337372
1223333523332243233132232332232223335335322323525322321334253333332323332533333517335353454323533223
4341437444333434323332333383423324432334353314128323534343344343334432154544343354162334333334354223
3226222346642252223631222337433121222224221622216145222252232446252342322122222234222322222325222341
2322154512252221221222213714342421221422226227211322247212222252224232222312312223421222234221532221
4277666476564646666636626617632542654642124484356434552454644676322636365366654435524567623648665645
4326224251324511325445265235322123123134324131225323445323442349342222222355534412243223435424754223
2322222132112221222122212212222522252222722242222224214422222223264222222222252222233222222221112222
2324232122242332222222242221332221213324334323232222412222222222222222224223222142222212222212321212
5311236232323322323422313262214232324232532322334323342351243423323223336232323332331123223222222212
3266355733331546543725353338633394673355295863352513444433679544569528558382293953841353213138855383
5221322222122222722222362222222112747121221212222222331224721222422242221825322222252212222222517222
1225242246213315532223222232331732223421223323116522132322122232231532233133121222822222462132133232
2221326812226423812362221223211116525411823421279171513527321224217226242124244542225824262212224351
4453425564443325353335233324434534363336223333422622636323343533343244433436456533432334323233334362
3224232512141532361423211324223522252221342256222223212234123221322422322242321222232222247422253222
6125122313322332232213332221223133535333332422313523321243243222232215243223221535432223335333234523
1351678243754931425378943558344359229876853933447853352374345385533544635655973754647345363157934433
4244122244422342343123435242374137343342123432243334242222123211312232244453344324374231231324554252
2322353332422513334235125325633252242233252413323412222522323325155334324223233211523224223352123324
5313436256323342326122534332142462233522466423222235523454546145825561325814532466226535435225486422
5434443545444364645323442442456213744146245265734444415252259444643332333464442244443545345639431334

4
day3/test_input Normal file
View file

@ -0,0 +1,4 @@
818181911112111
987654321111111
811111111111119
234234234234278

2
day4/CMakeLists.txt Normal file
View file

@ -0,0 +1,2 @@
# Use top-level helper to add the target and copy input files
aoc_add_day(day4 "${CMAKE_CURRENT_SOURCE_DIR}" main.cpp)

166
day4/main.cpp Normal file
View file

@ -0,0 +1,166 @@
#include <array>
#include <cstddef>
#include <expected>
#include <fstream>
#include <iostream>
#include <mdspan>
#include <print>
#include <ranges>
#include <string>
#include <vector>
struct Diagram {
std::vector<int> data;
size_t width;
size_t height;
using GridView = std::mdspan<int, std::dextents<size_t, 2>>;
auto grid() { return GridView(data.data(), height, width); }
};
namespace {
auto printMap(Diagram &diagram) {
auto grid = diagram.grid();
for (auto row = 0UZ; row != grid.extent(0); row++) {
for (auto col = 0UZ; col != grid.extent(1); col++) {
std::print("{}", grid[row, col]);
}
std::println();
}
// std::println("Map: {}", diagram.data);
std::println("Width: {}", diagram.width);
std::println("Height: {}", diagram.height);
}
auto parseMap(const std::string &filename) -> std::expected<Diagram, std::string> {
std::ifstream inputF{filename};
if (!inputF) {
return std::unexpected{"Some file open error.\n"};
}
Diagram diagram{};
std::string puzzleLine{};
while (std::getline(inputF, puzzleLine)) {
// std::println("{:3}: {}", diagram.height, puzzleLine);
diagram.data.push_back(0);
diagram.data.append_range(puzzleLine | std::views::transform([](char c) -> int { return c == '.' ? 0 : 1; }));
diagram.data.push_back(0);
diagram.height++;
// ugly
diagram.width = puzzleLine.length() + 2;
}
// also ugly, bound it with 0s
diagram.data.append_range(std::vector<int>(diagram.width, 0));
diagram.data.insert_range(diagram.data.begin(), std::vector<int>(diagram.width, 0));
diagram.height += 2;
// printMap(diagram);
// auto ms2 = std::mdspan(diagram.data.data(), diagram.width, diagram.height);
return std::move(diagram);
}
auto countMovablePaper(Diagram &diagram) -> long {
long nMovablePaper{};
auto grid = diagram.grid();
for (auto row = 1UZ; row != grid.extent(0) - 1; row++) {
for (auto col = 1UZ; col != grid.extent(1) - 1; col++) {
if (grid[row, col] == 1) {
// std::print("checking [{},{}]:", row, col);
// shitty kernel
int upLeft = grid[row - 1, col - 1];
int up = grid[row - 1, col];
int upRight = grid[row - 1, col + 1];
int left = grid[row, col - 1];
int right = grid[row, col + 1];
int downLeft = grid[row + 1, col - 1];
int down = grid[row + 1, col];
int downRight = grid[row + 1, col + 1];
// caveman shit
if ((upLeft + up + upRight + left + right + downLeft + down + downRight) < 4) {
// std::println("Found");
nMovablePaper++;
}
}
// std::println();
}
}
return nMovablePaper;
}
auto moveMoveablePaper(Diagram &diagram) -> long {
long totalPaperRemoved{};
auto grid = diagram.grid();
constexpr std::array<std::pair<int, int>, 8> offsets = {
{{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}};
while (true) {
long currentPaperRemoved = 0;
for (auto row = 1UZ; row != grid.extent(0) - 1; row++) {
for (auto col = 1UZ; col != grid.extent(1) - 1; col++) {
if (grid[row, col] != 1) {
continue;
}
// std::print("checking [{},{}]:", row, col);
// shitty kernal
int neighbors{0};
for (auto [dr, dc] : offsets) {
// mdspan allows [x, y] indexing natively
neighbors += grid[row + dr, col + dc];
}
if (neighbors < 4) {
grid[row, col] = 0;
// std::println("Found");
currentPaperRemoved++;
}
}
// std::println();
}
if (currentPaperRemoved == 0) {
std::println("Didn't remove any more paper this iteration! Stopping.");
break;
}
totalPaperRemoved += currentPaperRemoved;
// printMap(diagram);
}
return totalPaperRemoved;
}
} // namespace
auto main() -> int {
auto testCase = parseMap("test_input");
if (testCase) {
// auto testResult = countMovablePaper(*testCase);
// std::println("P1 Testcase result: {}", testResult);
auto testResultP2 = moveMoveablePaper(*testCase);
std::println("P2 Testcase result: {}", testResultP2);
} else {
std::print("{}\n", testCase.error());
}
auto realPuzzle = parseMap("puzzle_input");
if (realPuzzle) {
// auto realResult = countMovablePaper(*realPuzzle);
// std::println("P1 Real result: {}", realResult);
auto realResultP2 = moveMoveablePaper(*realPuzzle);
std::println("P2 Real result: {}", realResultP2);
} else {
std::print("{}\n", realPuzzle.error());
}
return 0;
}

137
day4/puzzle_input Normal file
View file

@ -0,0 +1,137 @@
.@@@.@@@@@.@@.@@@@.@@@@.@@@@..@@@@.@@@...@@@@.@.@@.@@@.@@@@@@@@@...@.@@@@@@..@..@@@.@@@.@@.@@@@@@.@@@@.@..@@@@@.@@@....@@@@@@..@.@@.@.@@@
@@.@@@@.@.@@.@@...@.@..@@.@.@.@....@.@@@.@@.@.......@@..@.@..@@@@@.@@.@..@@....@@@.@@@.@@@@...@.@.@@.@@@.@@@@@@@@@@..@.@@.@@.@.@@..@@@...
@..@..@@@@@@@.@@@@.@.@@.@@..@@.@@@@@@@@@@@@@@@@@@@.@.@@...@.@..@@@@.@@.@..@@@@@.@@@@..@@.@@@@@@@..@.@@@@@@@@@@@..@@@@.@@@.@@.@@@...@@.@@@
@@@.@@@@@@..@@@@.@@@@@@...@..@@@@.@..@.@@..@@@@..@@@.@@@..@.@@@@....@.@@@..@@.@.@.@@..@@@@@@.@@...@..@@@@@@@@@@.@@@@@...@..@@@.@@..@@@.@.
.@@@@@@.@@.@..@.@@.@@@@@@@@@@@@@@@@@@@@@.@@@@@@@.@@.@..@@@@@...@@@.@@@@.@..@@@...@..@@.@@@@@@..@@@@@.@...@@.@.@@......@..@@@@.@..@.@@@.@.
@@@@.@@@@.@@@.@@..@.@.@@..@@.@@@@....@.@@.@@.@@@@@.@@@.@@@@@@@.@.@..@@@@@@@@@.@@@@@@@@..@.@@@@@..@.@@.@.@.@...@@@.@@@@@..@....@@@@.@.@@@@
@@@@@@@@..@@@..@@@@@@@.@@@@..@@@.@..@@@.@...@..@..@@.@.@@@.@.@@...@@...@.@.@..@@@@...@@..@@.@@.@...@@@..@@@@.@@.@..@@@.@@@.@..@..@@.@...@
.@@.@@@@@@@@..@@@@@@.@@.@..@.@.@@@.@@@@.@@.@@...@@@.@@.@@..@@..@.@.@@@..@@.@@@@....@.@..@@@@.@@@@@.@@@..@@..@..@.@.@@.@@@@..@@...@@@.@@@@
@@@@@@.@.@@@@@@@...@@@@@@.@@.@@@@@.@..@@@@..@@@@@@.@@@@..@@.@@.@@@..@@@.@@@@@@@...@@@@@.@.@.@.@@@@@@.@@@@@@@@@.@..@@@@@@@@.@.@@.@@.@.@@@.
@...@@@@@@@@@@@@.@@@......@@@.@.@.@.@@.@@..@@@@@.@@@@@.@@.@....@@@.@.@@@@@@@@@...@@@@.@@@..@@@.@@..@@@@...@.@..@@@...@.@@..@..@.@@@@@..@.
@@.@@@....@@@.@@@@@.@@@.@@@@.@@@@.@@@@@.@@@.@@.@..@.@@@@..@...@.@@@@@...@@.@@..@..@@.@.@@.@@@@.@@.@.@.@@.@@@.@@@@@@@@@@@@@@..@..@@@..@@@.
@..@.@@.@@@@.@@.@@@@..@@@@..@@.@@.@..@.@@@@@.@..@.@..@@@.@@.@@@..@@.@.@@@@@@@@.@@@.@@@.@@@.@@@@.@@...@@@.@.@@.@@..@@..@.@.@@.@@@...@@@@@@
@@@.@@@@.@@.@@@.@@@@.@@@.@@@.@@@@.@@@@@@....@@@...@@.@.@.@.@@@.@.@@@....@.@@@@@..@@@@@@@.@..@@@.@..@@@@.@@@.@@@@@@.@.@..@@@@@@@@@@..@@@@.
.@@.@..@.@.@@@.@@@@.@@@@@.@@@.@@@@@@...@@@@..@@@.@@@.@@.@@.@@..@.@@..@@@@.@@@@.@@@@@@.@..@.@.@@@....@@..@@@@@.....@@@.@.@@.@@@.@.@@..@@..
.@@@@.@@@@....@.@@.@@..@@@.@@..@.@..@@.@@@.@.@@@..@...@.@..@@.@@@@.@.@.@@@..@@@.@@@@.@@@@.@.@@@@@@@@.@.@@..@.@@@@.@.@@.@.@.@...@.@@@@@...
@@@@..@@.@@@..@...@@..@@@@.@@.@.@..@.@.@@@@@.@.@@.@@@@..@@@..@.@@@@@@...@.@.@@@@..@@...@..@@@.@..@@@@@@@.@@@@.@@@@..@...@@@.....@@....@.@
@@.@@.@@@@@@@.@.@.@.@..@@@@.@@@@...@...@@.@..@..@@.@.@.@.@.@@@@@@@@..@@.@@@@@@@@..@@@@.@@@...@.....@@.@.@.@.@@@@.@@@@..@..@.....@@@@.@@@@
@@@@@@@@.@@@@..@@@@@@@@@.@@@..@@.@@@@@@.@@@.@@.@@@@@@@@..@@.@@.@.@@.@@@.@@.@@....@@.@.@.@@@.@@.@..@@@@.@.@@@@@..@@@.@@@@@@@@@@@...@@...@@
.@@..@@@@@.@@@@@.@@.@..@@@..@@@@@@@@..@@....@@.@.@@@@@.@@@.@@@@..@..@@...@.@@@.@@@.@@..@@@@.@.@@@@...@.@.@@.@@..@@@@@@@@@.@@..@.@@@.@@@@@
@.@@.@@.@..@.@@@@.@@@@.@@..@@.@.@...@@@@@@@@@..@@@@.@@@@@.@@.@@@@.@@@@@.@@.@.@@@.@...@@.@..@@@...@@@...@@@@@.@.@@@.@@@@..@@@@..@@@.@@@@@.
@@@..@@.@@@@@@@@@.@@@.@@@@@.@.@@@@.@.@.@@@@.@.@.@@.@.@@..@@@..@@@..@.@@.@@..@.@.@@@@..@..@.@@@@@@@@@@@...@.@@....@.@..@@..@@.@..@.@@@@@..
@.@.@@@@@@@.@.@.@@@.@@.@@@@@@@@@@@.@@@@@.@..@@@@@@@..@@@@@.@.@@@..@@@@@.@..@@..@.@@@@@@@.@@@..@.@@@.@@@@.@@.@@.@@@@@@..@@@.@@.@..@@@@.@@.
.@.@@@@@@...@@@.@@@@.@@@@@@@@@@@.@@@@.@@@@.@@.@@...@@...@@@@.@..@@@@.@@...@.@..@@@@@@.@@@@.@.@@...@@@.@.@..@.@.@@@@.@@@....@@@@.@@.@.@@..
@..@@@...@....@@@@@@@.@@.@@@@@@@.@@@@@@.@@@.@@@.@..@@.@@@.@.@@.@.@@@@@@@@@@.@@@@.@@@@@.@@.@..@@@@.@@..@..@...@@@..@.@...@..@@@@.@@@.@@@@@
.@@..@..@...@@@@..@.@.@@...@.@@@@@.@@@@@.@@@...@.@..@@@..@.@..@....@@.@@.@@@@@@@.@.@@@.@@@@@.@@@.@@@.@.@@@@.@@@@@@@.@@@@@@@..@...@@.@.@@@
@@@@@@.@@@@...@.@@@...@@@.@@.@@@..@@@.@.@@...@@@.....@@@.@@@@.@@@@.@.@@@.@@@@@...@@.@@.@@@.@@@@@@.@@@@.@@.@@@@@@@@@@@..@.@@.@@@@@.@@.@@@@
.@.@@@@.@@@@@@@.@@..@@@@@@@@....@@@...@@..@.@@@.@@.@.@.@@@@..@@...@.@@@@.@...@..@@..@@@.@@@@.@.@@@....@..@@.@@@@@@...@@@@@@@..@@@..@.@@.@
@@.@.@@@@@...@@@@@.@.@@@@@@.@@@@.@@..@@......@.@@@..@..@@@@@@.@@@@@@@.@..@@@@@@@@@@.@@@@@..@@@@...@.@@@.@@@@@.@..@@@@.@@@@@@.@@@@.@@@@...
@@.@.@..@.@@@@@@@.@.@@.@..@@@@@@...@@@@.@@@@@@@@.@@@@@@@.@@.@@@@@.@@@@.@@.@@@@...@.@.@@.@.@..@@@@@.@.@@.@@@@@@@.@..@@..@@.@@..@..@.@@@.@.
@@.@@@@@@...@@@@@@@..@.@@@.@..@...@@@.@@..@@@.@.@@.@@@@@........@@.@@.@.@.@.@@@@@@@@@@@.@.@@.@@@@@@@.@.@@@.@@@.@@@@@.@@.@@..@@..@@.@@@@.@
..@.@@.@@..@.@@..@@@@@.@@.@@@@..@.@.@@@@@@.@@@.@@@@@@..@.@@@@@@.@.@@@@@@.@.@.@@@@@@.@@..@.@.@@@@.@.@@@.@..@@@.@@@@.@@.....@.@.@.....@@@@.
.@@@@.@@@@@.@@.@@@@@@.@@@.@@@...@@.@.@@.@@@@@@....@@@@.@@.@@.@@.@@@@.@@.@@@@@...@@@@@.@@@@@..@..@@@@....@@@@..@.@@@@@.@.@@..@..@..@@@@@@.
@@@@@@.@.@@@..@..@@@.@@@.@..@.@@@@@@@@@@@.@.@@@@@..@@@.@..@@.@@....@@@.@@.@....@@@@@@@.@@.@@@@.@.@.@@..@.@@@@@...@.@@@@@@...@@..@.@@@@@..
@.@@@@@@.@.@.@.@@@..@@@@@.@@@.@@@@@..@.@.@@.@@.@@@.@@@@@@@@.@.@@@@@@.@@@@.@@.@@.@@.@.@@@@@@@@.@@.@@.@@.@@@@@@@@..@@@@..@@@......@@..@.@@@
.@@@@@.@@@@.@@@@@@.@@.@@@@.@@.@@@@.@.@@.@.@@@@@...@.@.@@@.@@@@@@.@@..@@@@@@@@@@@.@@@@.@@@..@@@@@@..@.@@@@.@@@.@.@@.@@.@@@@@@..@.@..@.@...
.@@....@.@.@.@@@.@@.@@@@@@@..@..@@..@@@....@....@@....@.@@.@.@@.@@@@@@@@@@@@..@.@@@@@.@.@@@@..@.@.@@.@@@@@..@@@@@@@@@.@.@@..@@@@..@@@..@@
@..@@@@@@.@@@@.@@@.@..@.@@@@.@@.@@@@@.@@.@.@@@@@@@..@..@.@@.@.@@..@@..@@@@@.@@@.@@@..@@@@@@@.@@@@@.@@.@@@@@@@@@@.@@@.@.@@@@@.@@@@@.@@..@@
@@.@..@.@@@@@.....@@.@@@@@@.@@@.@..@@@.@@@@.@@@..@.@@..@.@...@@@@@@@@.@@.@@..@@@@@.@@@@.@@.@..@@@.@@@@@@@@@...@@@@.@@@@@@@@@@.@@@@..@@@.@
@..@@@@.@.@@...@@@@..@@@.@@@@.@..@.@...@@@@@..@@@.@@@.@..@@..@@@@@@@.@@...@@.@@@@@.@.....@@@..@@...@.@....@@....@@@@@@@@@@@..@@@@@.@@@.@@
..@.....@@.@@@@@.@.@@@@@@.@@..@..@@..@@.@@@.@@.@.@@.@@@@@@.@@.@@@.@@@@...@.@.@.@@.@.@@..@@.@@@@..@@@@@.@.@.@@@@@.@@@@@@@.@@@@@@.@@@@.@@..
.@..@@@@@@@@@@.@.@.@.@@@.@@.@@@@@@@@@@.@@@.@.@...@.@@.@@@.@...@@.@@@@@@@.@@@.@@@...@@@.@@.@@@.@@@@@@@..@@....@.@.@@.@@@@.@.@.@@@.@@@@..@@
@.@....@@@@.@@.@.@@@@..@@@.@@.@@@@..@@@@@@..@@.@...@...@@@@@.@@@@@.@.@.@.@.@@.@@.@.@.@@..@.@@@.@@@.@...@@@.@.@@..@@@..@@...@@@@@@@@@@@.@.
@@@@.@.@@..@@.@..@@@@@@..@@....@..@@@@@@.@@...@@@@.@@@@.....@.@@.@.@@@@@@..@@.@...@..@@.@@@@@@.@@.@@@..@@@@@.@@@@@..@@.@@@.@@@@@@@..@@@@@
..@.@@@@@@.@.@.@@@.@@.@@@@@@..@.@.@.@@.@@@.@@@@...@@.@@.@.@@@..@@.@.@.@@@.@@@..@@@@@@@@@@@@.@@@@@@@@@@..@.@.@.@@@@@@@@@@@@.@@.@@.@.@.@@@@
.@..@@@@@.@..@@@.@@@@@@@..@@.@@...@@.@@@@@@@@@@..@.@@.@@.@@@@@@@...@@@.@.@@@.@@@@.@@@@@.@.@@.@.@@@@..@@@..@..@@@.@@@.@@.@.@@@@@@.@@@@@.@.
...@@.@@@..@@@@.@@@.@..@@@@@.@@@.@.@@.@@.@.@@@@....@@.@@..@@@.@@@..@.@@....@@.@@@@@@@@@@.@@@@.@@..@..@@@..@.....@..@..@@@@@@@.@@@@@@@.@@@
@@@@.@..@@@.@..@.@.@...@@@..@@@.@.@..@@.@@@..@@@@@@..@.@.....@.@@@@@.@@.@@@@.@@@@@@@@.@@@@@@@@@@...@.@@@.@.@@@@.@..@@.@@.@@@@.@@@@..@@.@.
@..@....@@@..@@@@@@@@@..@@@@@@@@.@.@@@@@@@@@@.@.@@@@...@@.@@@@@@...@.@.@@@....@@...@@@@@.@..@@.@.@@.@@.@.@.@@@.@@@@@@@.@@.@@@.@@@.@.@@@@.
@.@.@@@@.@...@@.@@@@.@@@..@@@.@@.@.@.@@.@@@.@@.@@....@@@@.@@@@.@.@.@.@@@@..@@.@@....@@@@@.@@@@@.@..@@@@.@.@@..@.@@@@.....@.@.@@@@@@.@@@@@
.@.@@@@.@...@@@.@@@.@@.@..@@@@.@@.@@@..@@@@..@.@@@@.@@..@@@@.@.@@.@@@.@@@..@@@@@.@@@@@@@@@.@@@.@@@..@.@.@.@@@.@..@@@..@...@..@...@.@...@@
@@@@@@@.@@.@.@.@@@.@@.@@@.@....@@.@@.@.@@@.@.@@.@.@@.@@@.@@@@@@@@@...@@.@.@@.@@..@.@@@..@..@.@..@@@@@@..@.@.@@@@@@.@@@...@@@@.@@.@@@@.@@.
@.@@@@..@.@.@.@.@@.@.@@@.@@@@..@@.@.@@@.@@@.@@@@@@@@.@.@@@@..@....@@..@@.@@..@@@@.@@.@@@@..@@@@...@@.@@@@@.@.@@@@.@@..@@@@@.@@@..@@@@.@@@
@@..@@.@@@.@..@..@@@.@@...@@@@@@@@@@.@..@.@.@@@@@.@@@@.@@@@@@.@@...@.....@@@@.@@@@@@@@@.......@@@.@@.@@..@@@@.@@@@..@@@@@@..@@..@@@@@@.@@
..@@@@@.@.@@@@@@@@@....@@.@.@.@.@@@....@@.....@.@@@@@@@@.@.@.@@@..@@@.@@.@@.@@@...@@@..@@..@@@.@@@@@@@.@@@@.@@....@@@@@..@..@@@.@.@...@@@
@@@@@@..@...@.@..@@@....@.@@@@@@@@.@.@@@.@@@@@@@@@.@@@.@@.@@..@.@@.@...@.@@@@.@@@@@@.@@@@@.@.@@.@@.@@@.@.@@@@.@@@@.@@.@@.@.@@.@..@@.@@@@@
@..@@.@.@@@@@.@....@@..@@@@@@@@.@@@@@@..@@@..@...@.@@@..@.@.@@.@@.....@.@...@@@@.@@.@.@@.@.@@@@.@@.@@.@@@.@@.@..@@@.@.@@@@..@@..@@.@@....
.@@.@.@@@@@@@@@..@.@@@.@@@@@.@@@.@.@@@@@..@@@@.@@@@@.@@@@@@@@@@.@.@@@@.@@.@.@@@@.@@@@@@@@..@@@..@@.@@.@@@.@.@.@@..@@@.@.@@@@.@@@.@@@.@@@.
@@@..@.@@.@@@..@@...@..@@@@@@@@@@@.....@.@@..@@.@.@..@@@@.@@.@...@@@.@@@@..@@@@..@.@@@.@@@@@@@.@.@@..@@@@@@@@@@@@.@.@@...@@@@@.@@@......@
@@@@.@@@@@@.@@.@...@@@...@@@@...@.@.@@.@.@@..@@..@@@.@@.@@.@@@.....@@@@@.@..@@@...@.....@@@@@.@@.@@.@@.@.@.@@@@@@@@.@.@.@.@@@@@@@.@@..@@.
@@.@@@..@@..@@..@@@@@@@@@@@..@.@@...@..@@@@@.@@.@...@@@@..@@@.@@@@.@@@..@@.@@....@@..@@@@.@@@@.@@..@@@@.@@@.@..@@@@..@....@@...@@@@@@@@..
.@.@.@@@..@..@@.@.@@@@@@..@@@@.@@@@....@@@@@@.@@.@@@.@.@@....@.@@.@@@.@.@@.@@.@@.@..@@@.@@@.@.@.@@@.@@@@@@.@..@@@..@.@..@@@@@@@@@@@@@@@@@
..@@.@.@@.@@@@@.@@@@@@..@@@@@@.@.@.@@@..@@@@@@.@@@@@@@@...@@..@@@@@@@@@@..@@.@.@@.@@@@@..@.@@@@.@@@.@@@@@@@@.@@.@@@@.@..@@..@.@@..@@@@@@.
@..@.@@@@@@.@@@..@@..@@..@@..@@@@.@.@@.@@@@@.@..@@@@..@..@@.@@@@.@@@...@...@.@.@@.@@..@@.@@@@.@.@.@@@@.@.@..@@@.@@.@.@@.@@..@@@@@@@..@@@@
@@.@@@@@.@@@.@@@..@@.@@..@.@@..@@@@.@@@..@..@@@@@@.@@@@.@.@@@@@@@.@..@@.@...@@...@@@@@...@@@@@@@.@@@@.@@.@@@@@@.@@@@@@@.@@.@..@@.@@@@@.@@
@@@@@.@@....@@@.@@@.@.@.@.@@@@@@@@@@@@@.@@@@@@.@..@@@@@.@.@@.@.@@@@..@@@@.@@..@@..@.@@...@@.@.@@.@@@@@.@@.@@@@@@.@@.@.@...@..@..@@@@@@@@.
.@@@..@.@..@@@@@@.@@..@.@@@.@@@..@.@.@.@@@.@.@..@@@@@@.@@@@@.@@@.@@@@..@.@@.@@@@@@@...@@@.@@....@@.@@@..@.@.@@@@.@@@..@@@.@.@@..@..@@.@@@
@@@.@@@@@@.@@@.@@@.@.@@@@.@@.@.@...@@.@.@.@@@...@@@.@..@@@@@@.@.@.@@@@@@@@@@@@..@@@@@.@@.@.@.@@@@..@@@@.@@..@..@....@.@@@.@..@@@@@..@@@@@
@@.@..@@@..@@.@@@@@@@.@@.@..@@@.....@@@@.@@@.@.@@.@@..@@.@@@.@@.@@..@@@.@@@@.@@@@..@.@@.@.@@@@@@@.@@@..@.@.@@@@..@@..@@@@@@.@@.@@@@.@@@@.
@..@@@.@..@@.@@.@@.@.@.@@@.@..@@@@@.@@.@@......@@@.@@.@...@@@.......@@..@@...@@@@@.@@@@@@@...@@@@..@@..@.@@.@@@@@.@.@..@@@@@.@@@@@.@..@.@
@@@.@.@.@@@@@.@.@@...@@@.@.@@@.@@@@@@.@@.@@.@@.@@@.@.@@.@@...@@@@@@@@@....@@@.@.@@.@..@@.@@@.@.@.@.@@@@@..@@@..@.@@.@.@@@@@.@.@@..@.@.@@@
@.@@@@.@.@@@@@@.@.@.@@@@@@...@@@@..@@@.@..@.@@@@@@.@@@....@@@@.@.@@@@@.@@@.@@@@.@@@@@..@.@..@..@.@@@..@@..@..@.@@..@@..@..@@.@@@@......@@
@.@@.@@@.@@@@@.@@@@@@.@@@@.@@@@@.@.@@.@.@@@.@.@....@.@@..@@@@@@.@.@..@..@@.@@@.@@@@....@@@.@@.@...@.@@@@.@@@@..@@@.@.@@@..@.@....@.@@@..@
@...@..@..@@.@.@@@....@@@.@@@@@@@@@.@@.@@@@..@@.@.@@..@@..@@@@@...@@...@@@.@..@@.@@@@.@.....@.@.@@.@@@@@@.@.@@@@@@..@@.@.@@@..@.@...@@@@@
.@@@@@...@.@@..@..@.@@@@@@....@@@@@@@@@@@@@@@@.@@@...@..@@.@..@@@@...@.@.@@@@..@.@@.@@.@.@@.@.@@.@.@.@@@@@@.@@@.@@..@.@@@@@..@@@@..@@@@..
.@@@@@@@@.@.@@@@@@.@.@.@@@@.@@.@@.@.@@@.@@@..@.@@..@....@..@.@@...@@@@@@@@@@.@.@.@@@..@@@@@@.@@@@@.@@....@@@@@@@@@@.@.@..@@....@@@@@@@@.@
@.@@@..@@@@.@.@@.@...@.@@..@.@@@@@@@.@@@.@@.@@.@..@@.@@@.@....@@@@..@.@.@..@@@@@@..@@@@@@@.@.@@@@@.@.@.@.@@.@....@@@..@@..@@@@.@@@.@@....
.@.@.@@@.@@@@@@@@.@@@.@@.@@@.@@@@@@.@@..@.@@@@@@@@@@.....@@.@@@.@@@@@..@@@@.@@.@@.@@@@@@@.@@.....@..@@@@@@@@@@@@.@.@@@@@@.@@.@.@@@.@.@@.@
@....@..@.@..@....@@.@@@.@@..@@.@@@@@.@@@@@@..@@@..@@.@...@....@.@..@.@@@@@@@...@@@@.@@@@@@@@@.@.@@..@@@@@@@@@.@..@.@@.@@@@@@@.@@@@..@@@.
@@@@@@.@.@@@@@@.@@..@@..@.@.@@.@.@.@@..@.@@..@@@.@@@@@@@@...@....@.@.@@@.@..@.@.@.@@.@...@@..@....@@.@.@@@@.@..@..@.@@.@@@@@@...@@@@@@@@.
@@..@@@.@@@@@@.@@@@.@@@@@...@@...@@..@@@@@..@@@.@@@.@.@@..@@..@@@@.@.@.@@@.@@@@.@@.@..@@...@.@@..@@.@.@@@@...@.@@@@@@@@..@@@@.@.@@@...@.@
.@@@@..@.@@...@.@.@@@@@@@@..@@@.@@@@.@@..@..@..@.@@@.@.@.@@.@....@@.@..@@.@.@@..@.@@.@@@@.@@@@..@...@@@@.@@@@@.@@@.@@..@@@.@@@.@@@@@@@@@.
@@@@@@..@.@.@@@@@.@@@@@@..@@@@@.@@@@.@..@@@.@@@..@@....@.@@.@@@@@..@@.@.@@@@@.@.....@@@.@@@@.@..@@@.@@@@.@.@@.@@@@.@@@@..@@.@@.@@..@@@@@@
@@@..@@.@....@@.@@....@@...@.@..@..@@@@@.@...@@...@.@@@@.@@..@@.@@@@@@@.@@@@@@.@@@@@..@@@@@@..@..@....@...@.@.@...@@@.@@@@.@@....@@..@@..
@.@..@@.@@.@@@..@@@.@..@@..@..@@.@.@@@.@@@@@@@@.@..@.@@@...@@@@.@@@@@@...@.@@@@@@.@@@@@.@@@@@@@..@@@.@.@@@@@@@@@.@@@@...@.@@@@@.@@@@.@@.@
@@.@@@..@.@@@@@@@@.@..@.@.@.@@@.@@.@@.@@@@...@@.@@@@@.@@@...@..@@..@@@.@@..@@@@@.@..@@@@@@@...@@.@.@@@@@@.@@@@@.@@@@.@.@@@@@@.@.@@@.@..@@
.@.@.@@@..@.@.@.@@..@@@@@.@@@@@@@...@@@.@@@@@@.@@.@@.@@@@@.@.@@@.@...@.@@.@.@...@......@@@@@@@@@..@@...@@@@@.@@.@@@@..@@@@@@.@..@@@@@@@@@
.@@@.@.@..@@@@.@@@@@.@@@.@@...@@@@..@@@@@.@@.@@@.@@@..@@@.@@@@..@.@.@@@@@@.@@@.@.@@@@@@.@@@.@@@.@@@.@@@..@..@.@@@@@@@@@..@@.@@@@.@@.@@@..
.@..@..@.@@.@@.@@@@@@.@.@@@@.@..@.@..@.@..@@.@@..@@@.@.@.@.@..@..@.@@....@.@.@@@.@@@@@..@@@.@@.@@@@@@@@@@@@.@@@.@.@.@..@@@@@.@@@@@@@@@@@.
.@@.@@@@@@@.@...@@.@@@@....@....@@@.@.@.@@..@@....@.@@@.@...@.@@...@@..@@@.@..@@..@.@@.@@.@@.@@.@..@@@..@@.@.@@@@.@.@@@@@@.@@@@@@@@@@@.@@
@@@.@@.@@@.@.@@@@@@@..@@@@@@@@..@@@.@@@@@.@@@@.@@@.@@@...@.@.@@@.@.@.@@@@@.@.@@.@@..@@@@.@@@@@@.@@..@@@@@@@@@@.@@@.@..@.@@@@@@@.@@@@@@@@.
@.@.@@@.@@@@@......@@@.@@.@.@@@@@.@@.@@..@.@@.@@....@@@@@@.@.@@.@...@@.@@@@.@@@@@@@@@@@@@@@@@.@...@@@@.@@@@@@@.@.@@@.@@.@@@...@.@@..@.@@@
@..@@@@@@@@.@.@.@@@..@@@@@.@@..@.@@.@@@@@@@@@@.@@..@.@@..@.@@@@.@@.@@@.@@.@@@@@@.@@@..@.@@@@@@@@@..@.@@@.@@..@@@@@@@@.@@@@.@@@@@@.@..@@@@
.@@@@.....@.@..@@@..@@.@@@@...@.@@@@@.@....@@@@@.@...@.@..@....@.@@@@.@@@@@@@..@@..@.@@@@@@.@.@@@@@..@.....@.@.@@@@@@@@@.@..@@.@..@..@.@@
@@@.@@@.@..@@@@.@@..@@@@@.@@..@...@.@...@@@@....@@@.@@.@@@@..@@@@@.@@@@@@..@@@.@@@.@.@@@@@@@@.@@.@@.@.@.@@@.@.@@..@@@@..@@@@.@@.@@@.@@.@@
..@@.@.@.@@@@@.@@@@.@.@.@....@@.@@.@@@.@@.@@.@@.@.@..@@@@...@..@.@@@.@.@..@@.@@@@.@@@.@@.@@@.@@.@@..@...@@..@..@@@..@.@@.@...@@@@@.@.@@..
@@@@@.@@@@@@@@@@..@@.@@@....@@.@@@.@..@..@.@...@@@@@.@@.@@@.@.@.@@.@@.@..@@..@@@@@@@@.@..@@@.@.@@..@@@@@@@@.....@@.@@@.@@@@@..@......@@@@
@@.....@....@@@@.@..@@@@.@@@.@@@@@@@@@...@@.@@..@..@.@.@@..@@@..@@@@@@@.@.@@@.@.@@@@.@.@.@@@.@@@@@.@@@.@..@..@@.@@@@@@@@@...@@@@.@.@.@@@@
.@@@@..@.@@@.@.@.@@@@.@.@..@@.@@@@.@@@@@@@@@@@@@@@@.@.@@..@....@..@@@.@@@@@@@@.@@@@@.@@@@@.@.@@....@..@@@.@@..@....@@@@@@.@@@@....@@..@@@
@@@.@.@@@@......@@...@.@.@@.@@@..@@@.@.@.@.@@@@@@.@@@.@@..@@@.@@@@....@@@@.@@@@..@@.@@@.@@@@.@@@@@@@.@@@..@@.@.@@.@.@@@@@..@@..@@..@.@@.@
@..@@@@..@..@.@@@.@@@..@@@@@..@@.@@@.@.@..@..@@.@.@@@@@@@@@@.@@.@@..@..@@@.@@@.@@@@@....@@@..@@.@.@@@.@@.@@@.@@...@@..@.......@.@@@@@@.@.
@@.@@@@.@..@..@.@@@..@.@@@@@@.@.@..@..@.....@@@..@@@..@..@.@@.@@@.@.@@.@.@@.@....@@..@@@@@@@@@@@@...@@.@@@..@@.@@@@.@.@@..@@@@@@@.@@@.@@@
@@@@@..@.@@@@@@...@.@@@@@.@@@.@@.@.@@@.@.@@.@@@@.@...@@@.@..@@.@@.@..@@@@.@.@@.@@@@..@@@@@@@.@@@@.@.@@@@...@.@@@@@@...@..@.@@@.@@....@.@@
.@@.....@@@@@.@.....@@.@.@.@..@@.@..@@.@..@@.@.@.@@@@.@.@@@@@.@@@@@@.@..@.@.@@@@@@@@...@@@@.@@.@@@@@@@@@@@@.@@...@...@@.@@...@@.@.@@.@@@.
@....@@@@@.@..@..@..@@.....@@@@..@@.@..@@@@@@.@.@@@@@.@@@.@@..@@@.@...@@..@.@@@.@.@@..@....@.@@@..@@@@.@@@..@@..@@@@...@@@@.@...@@@.@@@@@
@@.@..@..@.@..@@@..@@@@.@@@@..@@......@@@.@.@@@...@@.@@@@@@@@@@.@.@@..@@..@@..@@@@@@@@@@@@@.@...@.@.@@@@.@@.@.@@...@..@.@.@...@@@@@.@@@@@
@@@@...@@@@..@@@..@...@@.@@@.@@@@@..@@@@.@..@.@@@@@......@@.@@...@@.@@@@.@@.@..@.@@@.@@@@@.@@@.@@..@@@..@@@@..@.@.@@.@@@@@...@.@...@...@.
@.@@@..@@.@.@@@@@..@..@.@@.@@@@.@@.@.@@..@@@@@@@@..@.@@..@..@.@@..@..@@..@@..@@@@.@.@.@.@.@@.@@@..@.@@@.@....@.@@@@@...@.@@.@...@@...@@..
.@@.@@@...@@@..@@.@@..@@.@.@@..@@@......@@.@@@....@@@@@.@@@@..@@.@....@@@..@@@@@.@@@...@@@.@@.@@@.@.@@@@@.@.@.@@@@@@.@.@@@@@..@@..@@...@@
@@@@@@@@...@@...@@@@@@@.@.@@.@@@.@.@.@@..@.@@..@.@.@.@@@@@@..@@@@.@@@@@...@@....@@@@.@@.@@.@..@.@@.@@..@@@@.@@@@.@@.@.@@...@@@.@@@..@@@..
@...@..@@@@@..@@...@.@@@@.@.@.@@@@@@.@@.@.@@...@.@..@@@@@.@.@.@@.@.@.@@@.@@.@@@@@@@@.@@@.@..@.@@@.@@@@@@.@@.@@.@@..@@.@@.@@@..@.@@.@@@@@.
.@@@.@@....@@@@@@.@@@@@@@@@@@.@.@.@@@.@@@@@@@@..@@@@@.@@@@@.@@.@@@.@@@.@..@.@@...@@...@@.....@.@@@@.@@.@@.@@@.@.@..@.@@@..@..@@@.@.@@.@.@
@.@@.@@@@.@.@.@@..@..@@@@..@@.@@@@@.@@@..@..@@@@.@@.@@@...@@@@@@@@@.@@@@@@...@@@.@..@@@@.....@.@@@@@..@.@..@@@..@.@@@.@@@.@@@@@..@.@@@...
.@.@@@.@.@...@.@@@.@.@@@@@@@@@@.@@...@..@@@.@.@@@.@.@@@@@..@@@@@@@@@@@.@@@@..@.@@@@@@@@..@@..@@@@@@@@..@@...@@@@@@@@.@.@@@@@..@@@.@.@@@@@
..@@.@..@@.@@@.@@@@.@.@.@@..@@.@@...@.@.@@@@@.@...@@@@...@@@..@...@@@....@@@@@.@@@@.@@@@@@.@.@@@@.@.@@@.@@@.@@.@.@@.@@.....@@@...@.@@@@@@
@@@@.@@@@@.@@.@.@.@@@@@@@@@..@@@@@@@@@..@.@@@.@@@.@@@@@.@@@@@.@.@@@@.....@.@.@@@@@@.....@@.@.@@.@..@@@@@.@..@.@..@...@@@.@..@.@@@@.@.@@@@
@@@@.@@@..@@@.@@@@@@@@@.@@@@@@@..@.@@.@@@@.@@@..@.@..@@.@@...@@@@@.@.@@...@..@@@..@@.@.@@@@.@@@@@@@@@@@....@@.@@.@@@...@.@.@@@@.@@@.@@@.@
@@@.@..@@@@@.@@.@@..@.@@@..@@@@@@@.@@@.@@@@@@.@@.@...@@@.@@..@@@@@.@@..@@@@@@@@.@@....@@....@@@@@@@@.@.@.@@@.@@.@.@@@@@.@.@@.@@@.@@@@.@.@
.@@.@@@@..@@@.@.@.@@@@@@@@@@@..@..@@@@@@@@@@@..@@@.....@@@@.@@@@@@@..@@..@@@..@@@@@@..@@.@@@@@..@@@@.@.@@@@..@@@@@...@.@@@.@@@@@@.@@@.@@@
@@..@.@.@@@@@.@@@.@@@@@@.@...@.@@.@@@..@..@.@@@@.@@.@@@@@@@..@.@@@@@@@@.@..@.@@@...@@@.@@.@@@@@@.@@@@@@..@...@@@@.@@.@@.@.@.@@.@@.@@.@.@@
@.@@..@@...@@@@@.@@.@..@@@@@@.@@@.@.@@.@@@@@@@..@@@@@@.@@@@.....@@.@@@@..@@@...@@..@..@@@@.@@@@@@@@@..@.@@@@@..@@@.@@.@@@.@..@@@@@@.@@@@@
@@@@@@@@@@..@.@.@@@@@..@@@@..@@.@@@@@..@@@@.@.@@@@@@@.@@@@@.@@@@.@.@@@@@@@@@@@@@@@..@@@@@@.@@@@@.@@@@@....@.@@.@@.@...@@@@@@@@.@.@@.@..@@
..@..@@@@@.@@@@@.@@@@@@@.@@..@.@@.@@@@.@@@@@..@.@.@.@@.@@...@@@@@@@@...@..@..@..@.@@@...@@...@@.@@..@@@@.@....@@@@@.@@@@.@@@@@.@@.@@@@@.@
@@@.@.@@...@@......@.@..@@@.@@@.@.@@.@@@..@@@@.@.@@@@.@@.@.@.@@@@.@@@@@@.@@@@@@.@@@..@@......@@@@@@@.@@@@@@@@.@@@@@@@..@.@@@..@.@..@@@.@@
@@@@.@@...@@..@@@@@@@.@@@...@.@@.@.@@@@@@@@@@@@@@@.@@.@@.@@@..@..@..@@.@.@.@@@@@@@....@@.@@@@.@.@@@.@@@@@@..@.@@.@@@...@.@@@.@@@..@@@@..@
.@@.@.@@@.@....@@.@@@@..@@@@..@@@.@@@...@@..@@@@..@.@.@@@@@@@.@@@@.@.@@.@@....@@.@@@@.@@@@.@.@.@@....@.@@@...@.@...@...@..@.@@@@@..@@@.@.
..@@@@@@@.@@.@..@@@..@.@....@@..@@@@@.@@@..@@@.@@@..@@.@@@.@@@@@@@.@.@@..@@@@.@.@@@......@@..@@@.@@@@...@@..@@@@@.@.@@@@@..@.@@..@..@@@@@
.@@@.@.@.@.@.@@@@.@.@.@@..@@.@@@.@.@@@@@.@.@..@@@@@.@.@@.@@@@@@@@..@@..@@@@@@.@.@@@@.@@...@@@.@@...@@@@@@@@@.@@.@@@.@@.@@.@@...@@.@@.@.@.
@.@@@@.@@@.@@@..@..@..@@@@@.@.@.@@@@@@@.@..@@@.@.@.@@.@@@@...@@@.@.@@@@..@.@@....@@@@.@@@@.@.@.@@@@@@@.@@.@@@@..@.@@@.@@@@@@.@@@@@@@@.@.@
.@@@@@.@@@@..@@.@.@@@.@.@@@@@@@..@@.@@.@@.@.@.@.@@@@@@@@@...@.@@@@@@@..@@@.@.@.@.@@@@.@@@.@.@@@@@@@@@@@@@@@@.@@.@@@@@.@.@..@@..@@.@@@@.@.
.@@.@@@@@@..@@.@.@@@......@@@@..@@@.@@@.@@..@@@@@.@@..@.@@@.@@.@@@@@..@@@@.@.@@..@.@.@@.@@@.@@@@@@@..@@.@.@...@@@.@..@.@@.@@@@.@..@@@@@..
@.@@@@..@.@.@@@@@@@@@...@@@@..@.@@@..@@@@@..@..@.@@.@@.@@.@@@@.@@.@.@@@@@.@@@...@.@@..@.@@.@@@@@@@@@@@@@.@@@@@.@@.@@@..@@@@.@@@@..@@@@@@@
@@@@@@...@..@.@@@..@@.@@@@.@@..@@@.@.@@@.@@@@@@@.@@@@..@@@@@.@.@.@@@@@@.@@.@@@..@.@.@.@...@@@..@@@@@....@@@@@@@@@@...@@@.@.@.@@@.@.@@@..@
@.@.@@@.@@@.@.@.@@@@.@..@.@....@@..@@@@.@..@..@@@@@@@.@@@@@.@@@@@..@@.@...@@..@@.@@@@@@@@@.@.@@@@@@@.....@@@@@@@.@@@.@..@@.@@.@.@@.@@.@..
..@@..@.@@@.@@@@.@@.@@..@@.@.@@.@....@@@@@@...@.@..@@@@@@@...@...@..@....@@@.@..@@@@@@.....@@@@@.@@@..@.@@@@@@.@@@@.@@@.@@.@@@..@@@@@..@@
@..@.@@.@@@.@@@..@@@...@..@.@@@@@@.@.@@...@.@@..@..@@.@@....@....@@@.@@@@@.@.@@@.@.@.@@@@.@.@.@...@@@@@@@@...@@@@@@..@@@@@@@.@@@.@.@@@.@.
@@.@.@.@.@@.@.@@@@..@@@@@@@.@@..@@.@@@@@@@@.@.@@.@.@.@...@@.@.@@.@.@@@@@@@@@@@@@@.@..@.@.@@.@.@@@@.@@@@@@@@..@..@...@.@@@..@@@@.@.@@@@@@.
.@.@@@@@@.@..@@...@@@.@@@.@@@@@@.@@@.@@@@@..@@.@.@.@@@..@@@.@@..@.@.@@@@@.@..@@.@@..@@@@@@@.@..@@@@@@.@@.@@@@@.@.@@.@.@.@.@@@@@@@...@.@@.

10
day4/test_input Normal file
View file

@ -0,0 +1,10 @@
..@@.@@@@.
@@@.@.@.@@
@@@@@.@.@@
@.@@@@..@.
@@.@@@@.@@
.@@@@@@@.@
.@.@.@.@@@
@.@@@.@@@@
.@@@@@@@@.
@.@.@@@.@.