fix day 11 part 2
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
needed to reset the grid every time and also fully reset the game state
This commit is contained in:
parent
beb9fbba0b
commit
c70ac6a5d5
|
@ -18,7 +18,7 @@ namespace aoc2020.test
|
||||||
[DataRow(typeof(Day08), "1654", "833")]
|
[DataRow(typeof(Day08), "1654", "833")]
|
||||||
[DataRow(typeof(Day09), "138879426", "23761694")]
|
[DataRow(typeof(Day09), "138879426", "23761694")]
|
||||||
[DataRow(typeof(Day10), "1980", "4628074479616")]
|
[DataRow(typeof(Day10), "1980", "4628074479616")]
|
||||||
[DataRow(typeof(Day11), "2303", "")]
|
[DataRow(typeof(Day11), "2303", "2057")]
|
||||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||||
{
|
{
|
||||||
// create day instance
|
// create day instance
|
||||||
|
|
|
@ -9,16 +9,13 @@ namespace aoc2020
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Day11 : Day
|
public sealed class Day11 : Day
|
||||||
{
|
{
|
||||||
private readonly LifeGame _initialGame;
|
|
||||||
|
|
||||||
public Day11() : base(11)
|
public Day11() : base(11)
|
||||||
{
|
{
|
||||||
_initialGame = new LifeGame(Input);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
var prev = _initialGame;
|
var prev = new LifeGame(Input);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
@ -40,7 +37,7 @@ namespace aoc2020
|
||||||
|
|
||||||
public override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
var prev = _initialGame;
|
var prev = new LifeGame(Input);
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var next = prev.StepPart2();
|
var next = prev.StepPart2();
|
||||||
|
@ -118,7 +115,7 @@ namespace aoc2020
|
||||||
|
|
||||||
public LifeGame StepPart2()
|
public LifeGame StepPart2()
|
||||||
{
|
{
|
||||||
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 y = 0; y < _h; y++)
|
||||||
for (var x = 0; x < _w; x++)
|
for (var x = 0; x < _w; x++)
|
||||||
next.Grid[y][x] = Grid[y][x] switch
|
next.Grid[y][x] = Grid[y][x] switch
|
||||||
|
@ -127,6 +124,8 @@ namespace aoc2020
|
||||||
'#' when CanSee(y, x) >= 5 => 'L',
|
'#' when CanSee(y, x) >= 5 => 'L',
|
||||||
_ => Grid[y][x]
|
_ => Grid[y][x]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// next.PrintBoard();
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue