Add day 6, part 2 WIP
This commit is contained in:
parent
2d63375daa
commit
d0dae5159b
|
@ -3,14 +3,18 @@ Language: Cpp
|
|||
BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
AlignOperands: DontAlign
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
#AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
#BinPackArguments: true
|
||||
#BinPackParameters: true
|
||||
BreakBeforeBraces: Allman
|
||||
BreakBeforeConceptDeclarations: Always
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakInheritanceList: BeforeColon
|
||||
ColumnLimit: 100
|
||||
ColumnLimit: 120
|
||||
Cpp11BracedListStyle: false
|
||||
EmptyLineBeforeAccessModifier: Never
|
||||
FixNamespaceComments: false
|
||||
|
@ -39,4 +43,5 @@ SpaceBeforeCaseColon: true
|
|||
SpaceBeforeParens: ControlStatements
|
||||
|
||||
# Deprecated
|
||||
#AllowAllConstructorInitializersOnNextLine: true
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <bitset>
|
||||
|
||||
class GridPathData
|
||||
{
|
||||
public:
|
||||
bool isVisited{ false };
|
||||
std::bitset<4> isLoopingInDirection{ 0 };
|
||||
};
|
|
@ -15,7 +15,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <aoc/Grid.hpp>
|
||||
#include <aoc/GridPathData.hpp>
|
||||
#include <aoc/LinesSolver.hpp>
|
||||
#include <aoc/Point2.hpp>
|
||||
|
||||
class GuardGallivant
|
||||
: public LinesSolver
|
||||
|
@ -29,8 +34,12 @@ class GuardGallivant
|
|||
Point2 start_{};
|
||||
const size_t getStartDirectionIndex() const;
|
||||
const char getStartChar() const;
|
||||
const char getVisitedChar() const;
|
||||
const char getObstructionChar() const;
|
||||
void visitPosition(const Point2& current);
|
||||
size_t turnDirection(const size_t current) const;
|
||||
void tracePath();
|
||||
void visitPosition(const Point2& current, const size_t directionIndex, Grid<GridPathData>& pathGrid);
|
||||
void backtracePath(const Point2& current, const size_t directionIndex, Grid<GridPathData>& pathGrid);
|
||||
void backtraceTurn(const Point2& current, const size_t reverseTurnDirectionIndex, Grid<GridPathData>& pathGrid);
|
||||
size_t turnDirectionRight(const size_t currentDirectionIndex) const;
|
||||
size_t turnDirectionLeft(const size_t currentDirectionIndex) const;
|
||||
size_t revertDirection(const size_t currentDirectionIndex) const;
|
||||
};
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Point2
|
||||
{
|
||||
public:
|
||||
|
@ -42,3 +44,5 @@ class Point2
|
|||
Point2& operator-=(const Point2& rhs);
|
||||
Point2& operator*=(const int rhs);
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Point2& rhs);
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -81,3 +81,9 @@ Point2& Point2::operator*=(const int rhs)
|
|||
*this = *this * rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Point2& rhs)
|
||||
{
|
||||
os << "(" << rhs.x << ", " << rhs.y << ")";
|
||||
return os;
|
||||
}
|
||||
|
|
|
@ -97,11 +97,11 @@ TEST_CASE("[GuardGallivantTests]")
|
|||
TestContext test;
|
||||
SECTION("FullData")
|
||||
{
|
||||
test.run(std::make_unique<GuardGallivant>(), 4665, 0, test.getInputPaths());
|
||||
test.run(std::make_unique<GuardGallivant>(), 4665, 1688, test.getInputPaths());
|
||||
}
|
||||
SECTION("ExampleData")
|
||||
{
|
||||
test.run(std::make_unique<GuardGallivant>(), 41, 0, test.getExampleInputPaths());
|
||||
test.run(std::make_unique<GuardGallivant>(), 41, 6, test.getExampleInputPaths());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue