spaghetti
This commit is contained in:
parent
c74be75bbe
commit
a6fb39f168
|
@ -74,7 +74,9 @@ void day02::Calculate()
|
||||||
int safeReports = 0;
|
int safeReports = 0;
|
||||||
for (std::string line; std::getline(input, line, '\n');)
|
for (std::string line; std::getline(input, line, '\n');)
|
||||||
{
|
{
|
||||||
if (IsSafe(line))
|
std::istringstream iss(line);
|
||||||
|
std::vector numbers(std::istream_iterator<int>{iss}, std::istream_iterator<int>());
|
||||||
|
if (IsSafe(numbers, false))
|
||||||
{
|
{
|
||||||
safeReports++;
|
safeReports++;
|
||||||
}
|
}
|
||||||
|
@ -82,10 +84,8 @@ void day02::Calculate()
|
||||||
std::cout << safeReports << '\n';
|
std::cout << safeReports << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool day02::IsSafe(const std::string &line)
|
bool day02::IsSafe(const std::vector<int> &numbers, const bool secondPass)
|
||||||
{
|
{
|
||||||
std::istringstream iss(line);
|
|
||||||
std::vector<int> numbers(std::istream_iterator<int>{iss}, std::istream_iterator<int>());
|
|
||||||
int previousNumber = numbers.at(numbers.size() - 1);
|
int previousNumber = numbers.at(numbers.size() - 1);
|
||||||
bool increasing = false;
|
bool increasing = false;
|
||||||
bool decreasing = false;
|
bool decreasing = false;
|
||||||
|
@ -106,22 +106,14 @@ bool day02::IsSafe(const std::string &line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SafetyChecks(currentNumber, previousNumber, increasing, decreasing) == 1)
|
if (SafetyChecks(currentNumber, previousNumber, increasing, decreasing) == 1 && !secondPass)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (IsSafe(numbers, true))
|
||||||
{
|
{
|
||||||
// numbers.erase(numbers.begin() + i);
|
|
||||||
// if (i + 1 < numbers.size())
|
|
||||||
// {
|
|
||||||
// previousNumber = numbers.at(i + 1);
|
|
||||||
// } else
|
|
||||||
// {
|
|
||||||
// printf("wtf do i do here?");
|
|
||||||
// }
|
|
||||||
// //currentNumber = numbers.at(i);
|
|
||||||
// if (SafetyChecks(currentNumber, previousNumber, increasing, decreasing) == 1)
|
|
||||||
// {
|
|
||||||
safe = false;
|
safe = false;
|
||||||
return false;
|
return false;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
previousNumber = currentNumber;
|
previousNumber = currentNumber;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#ifndef DAY02_H
|
#ifndef DAY02_H
|
||||||
#define DAY02_H
|
#define DAY02_H
|
||||||
#include <string>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
class day02
|
class day02
|
||||||
|
@ -12,7 +12,7 @@ class day02
|
||||||
public:
|
public:
|
||||||
static void Calculate();
|
static void Calculate();
|
||||||
|
|
||||||
static bool IsSafe(const std::string &line);
|
static bool IsSafe(const std::vector<int>& numbers,bool secondPass);
|
||||||
|
|
||||||
static int SafetyChecks(int current, int previous, bool increasing, bool decreasing);
|
static int SafetyChecks(int current, int previous, bool increasing, bool decreasing);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue