Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
d0dae5159b |
@ -3,14 +3,18 @@ Language: Cpp
|
|||||||
BasedOnStyle: LLVM
|
BasedOnStyle: LLVM
|
||||||
AccessModifierOffset: -4
|
AccessModifierOffset: -4
|
||||||
AlignAfterOpenBracket: DontAlign
|
AlignAfterOpenBracket: DontAlign
|
||||||
|
AlignOperands: DontAlign
|
||||||
AllowAllArgumentsOnNextLine: false
|
AllowAllArgumentsOnNextLine: false
|
||||||
|
#AllowAllConstructorInitializersOnNextLine: true
|
||||||
AllowAllParametersOfDeclarationOnNextLine: false
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
AllowShortFunctionsOnASingleLine: false
|
AllowShortFunctionsOnASingleLine: false
|
||||||
|
#BinPackArguments: true
|
||||||
|
#BinPackParameters: true
|
||||||
BreakBeforeBraces: Allman
|
BreakBeforeBraces: Allman
|
||||||
BreakBeforeConceptDeclarations: Always
|
BreakBeforeConceptDeclarations: Always
|
||||||
BreakBeforeTernaryOperators: true
|
BreakBeforeTernaryOperators: true
|
||||||
BreakInheritanceList: BeforeColon
|
BreakInheritanceList: BeforeColon
|
||||||
ColumnLimit: 100
|
ColumnLimit: 120
|
||||||
Cpp11BracedListStyle: false
|
Cpp11BracedListStyle: false
|
||||||
EmptyLineBeforeAccessModifier: Never
|
EmptyLineBeforeAccessModifier: Never
|
||||||
FixNamespaceComments: false
|
FixNamespaceComments: false
|
||||||
@ -39,4 +43,5 @@ SpaceBeforeCaseColon: true
|
|||||||
SpaceBeforeParens: ControlStatements
|
SpaceBeforeParens: ControlStatements
|
||||||
|
|
||||||
# Deprecated
|
# Deprecated
|
||||||
|
#AllowAllConstructorInitializersOnNextLine: true
|
||||||
AlwaysBreakTemplateDeclarations: true
|
AlwaysBreakTemplateDeclarations: true
|
||||||
|
25
include/aoc/GridPathData.hpp
Normal file
25
include/aoc/GridPathData.hpp
Normal file
@ -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
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <aoc/Grid.hpp>
|
||||||
|
#include <aoc/GridPathData.hpp>
|
||||||
#include <aoc/LinesSolver.hpp>
|
#include <aoc/LinesSolver.hpp>
|
||||||
|
#include <aoc/Point2.hpp>
|
||||||
|
|
||||||
class GuardGallivant
|
class GuardGallivant
|
||||||
: public LinesSolver
|
: public LinesSolver
|
||||||
@ -29,8 +34,12 @@ class GuardGallivant
|
|||||||
Point2 start_{};
|
Point2 start_{};
|
||||||
const size_t getStartDirectionIndex() const;
|
const size_t getStartDirectionIndex() const;
|
||||||
const char getStartChar() const;
|
const char getStartChar() const;
|
||||||
const char getVisitedChar() const;
|
|
||||||
const char getObstructionChar() const;
|
const char getObstructionChar() const;
|
||||||
void visitPosition(const Point2& current);
|
void tracePath();
|
||||||
size_t turnDirection(const size_t current) const;
|
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
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
class Point2
|
class Point2
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -42,3 +44,5 @@ class Point2
|
|||||||
Point2& operator-=(const Point2& rhs);
|
Point2& operator-=(const Point2& rhs);
|
||||||
Point2& operator*=(const int 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;
|
*this = *this * rhs;
|
||||||
return *this;
|
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;
|
TestContext test;
|
||||||
SECTION("FullData")
|
SECTION("FullData")
|
||||||
{
|
{
|
||||||
test.run(std::make_unique<GuardGallivant>(), 4665, 0, test.getInputPaths());
|
test.run(std::make_unique<GuardGallivant>(), 4665, 1688, test.getInputPaths());
|
||||||
}
|
}
|
||||||
SECTION("ExampleData")
|
SECTION("ExampleData")
|
||||||
{
|
{
|
||||||
test.run(std::make_unique<GuardGallivant>(), 41, 0, test.getExampleInputPaths());
|
test.run(std::make_unique<GuardGallivant>(), 41, 6, test.getExampleInputPaths());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user