fix day 11 part 1
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Ben Harris 2020-12-11 15:45:24 -05:00
parent 405339031e
commit beb9fbba0b
2 changed files with 29 additions and 4 deletions

View File

@ -18,7 +18,7 @@ namespace aoc2020.test
[DataRow(typeof(Day08), "1654", "833")]
[DataRow(typeof(Day09), "138879426", "23761694")]
[DataRow(typeof(Day10), "1980", "4628074479616")]
[DataRow(typeof(Day11), "", "")]
[DataRow(typeof(Day11), "2303", "")]
public void CheckAllDays(Type dayType, string part1, string part2)
{
// create day instance

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
@ -22,7 +23,15 @@ namespace aoc2020
while (true)
{
var next = prev.StepPart1();
if (next.Grid == prev.Grid) break;
var same = true;
for (var i = 0; i < next.Grid.Length; i++)
if (!next.Grid[i].SequenceEqual(prev.Grid[i]))
{
same = false;
break;
}
if (same) break;
prev = next;
}
@ -35,7 +44,15 @@ namespace aoc2020
while (true)
{
var next = prev.StepPart2();
if (next.Grid == prev.Grid) break;
var same = true;
for (var i = 0; i < next.Grid.Length; i++)
if (!next.Grid[i].SequenceEqual(prev.Grid[i]))
{
same = false;
break;
}
if (same) break;
prev = next;
}
@ -58,12 +75,19 @@ namespace aoc2020
{
}
private void PrintBoard()
{
Console.Clear();
foreach (var line in Grid)
Console.WriteLine(line);
}
public int TotalSeated =>
Grid.Sum(l => l.Count(c => c == '#'));
public LifeGame StepPart1()
{
var next = new LifeGame {_h = _h, _w = _w, Grid = Grid};
var next = new LifeGame {_h = _h, _w = _w, Grid = Grid.Select(s => s.ToArray()).ToArray()};
for (var y = 0; y < _h; y++)
for (var x = 0; x < _w; x++)
next.Grid[y][x] = Grid[y][x] switch
@ -73,6 +97,7 @@ namespace aoc2020
_ => Grid[y][x]
};
// next.PrintBoard();
return next;
}