forked from Bananymous/banan-os
AOC2023: Remove unnecessary loop
This commit is contained in:
parent
00d57d783e
commit
58633ca373
|
@ -202,7 +202,7 @@ i64 puzzle2(FILE* fp)
|
||||||
{
|
{
|
||||||
for (u32& tile : row)
|
for (u32& tile : row)
|
||||||
{
|
{
|
||||||
// Remove left and right from path
|
// Remove left and right from path tiles
|
||||||
if (tile & Flag::Path)
|
if (tile & Flag::Path)
|
||||||
tile &= ~(Flag::Left | Flag::Right);
|
tile &= ~(Flag::Left | Flag::Right);
|
||||||
// Tile should never be both left and right
|
// Tile should never be both left and right
|
||||||
|
@ -227,11 +227,8 @@ i64 puzzle2(FILE* fp)
|
||||||
}
|
}
|
||||||
ASSERT(enclosed != Flag::Path);
|
ASSERT(enclosed != Flag::Path);
|
||||||
|
|
||||||
// Expand all enclosed areas
|
// Expand all enclosed areas (only one pass is needed since exery area
|
||||||
bool modified = true;
|
// is fully bordered by enclosed tiles)
|
||||||
while (modified)
|
|
||||||
{
|
|
||||||
modified = false;
|
|
||||||
for (size_t y = 1; y < grid.size(); y++)
|
for (size_t y = 1; y < grid.size(); y++)
|
||||||
{
|
{
|
||||||
for (size_t x = 1; x < grid[y].size(); x++)
|
for (size_t x = 1; x < grid[y].size(); x++)
|
||||||
|
@ -239,11 +236,7 @@ i64 puzzle2(FILE* fp)
|
||||||
if (grid[y][x] & Flag::Mask)
|
if (grid[y][x] & Flag::Mask)
|
||||||
continue;
|
continue;
|
||||||
if ((grid[y - 1][x] & enclosed) || (grid[y][x - 1] & enclosed))
|
if ((grid[y - 1][x] & enclosed) || (grid[y][x - 1] & enclosed))
|
||||||
{
|
|
||||||
grid[y][x] |= enclosed;
|
grid[y][x] |= enclosed;
|
||||||
modified = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue