cleaned up. restarting. getting the correct answer on part 1
This commit is contained in:
parent
a342582f69
commit
9e34e3e4bb
|
@ -100,36 +100,12 @@ void day02::Calculate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (IsUnsafe(currentNumber, previousNumber, increasing, decreasing) == 1)
|
if (IsUnsafe(currentNumber, previousNumber, increasing, decreasing) == 1)
|
||||||
{
|
{
|
||||||
numbers.erase(numbers.begin() + i);
|
safe = false;
|
||||||
if (i >= numbers.size())
|
break;
|
||||||
{
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
|
|
||||||
previousNumber = numbers.at(i - 1);
|
|
||||||
currentNumber = numbers.at(i);
|
|
||||||
|
|
||||||
|
|
||||||
// if (currentNumber > previousNumber)
|
|
||||||
// {
|
|
||||||
// increasing = true;
|
|
||||||
// }
|
|
||||||
// if (currentNumber < previousNumber)
|
|
||||||
// {
|
|
||||||
// decreasing = true;
|
|
||||||
// }
|
|
||||||
if (IsUnsafe(currentNumber, previousNumber, increasing, decreasing) == 1)
|
|
||||||
{
|
|
||||||
// continue;
|
|
||||||
safe = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
previousNumber = currentNumber;
|
previousNumber = currentNumber;
|
||||||
}
|
}
|
||||||
if (safe)
|
if (safe)
|
||||||
|
@ -145,22 +121,18 @@ int day02::IsUnsafe(const int current, const int previous, const bool increasing
|
||||||
const int diff = abs(current - previous);
|
const int diff = abs(current - previous);
|
||||||
if (current < previous && increasing)
|
if (current < previous && increasing)
|
||||||
{
|
{
|
||||||
//remove current
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (current > previous && decreasing)
|
if (current > previous && decreasing)
|
||||||
{
|
{
|
||||||
//remove current
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (current == previous)
|
if (current == previous)
|
||||||
{
|
{
|
||||||
//remove current
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (diff < 1 || diff > 3)
|
if (diff < 1 || diff > 3)
|
||||||
{
|
{
|
||||||
//remove current
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
//safe
|
//safe
|
||||||
|
|
Loading…
Reference in New Issue