public string Process2() { var previous = new SeatLayout(ToString()); foreach (var seat in _seats.Values) { if (seat.Status == SeatStatus.Floor) { continue; } var seen = previous.SeenFrom(seat.Row, seat.Column); if (seat.Status == SeatStatus.Occupied && seen.X >= 5) { seat.Status = SeatStatus.Empty; } else if (seat.Status == SeatStatus.Empty && seen.X == 0) { seat.Status = SeatStatus.Occupied; } } return(ToString()); }
public string Process() { var relativeAdjacents = new List <Vector2> { new Vector2(-1, -1), new Vector2(-1, 0), new Vector2(-1, 1), new Vector2(0, -1), new Vector2(0, 1), new Vector2(1, -1), new Vector2(1, 0), new Vector2(1, 1) }; var previous = new SeatLayout(ToString()); foreach (var seat in _seats.Values) { if (seat.Status == SeatStatus.Floor) { continue; } var position = seat.GetPosition(); var statuses = new List <SeatStatus>(); foreach (var r in relativeAdjacents) { var a = position + r; var status = previous.GetSeatStatus(a.X, a.Y); statuses.Add(status); } if (statuses.All(x => x == SeatStatus.Empty || x == SeatStatus.Floor)) { seat.Status = SeatStatus.Occupied; } else if (statuses.Count(x => x == SeatStatus.Occupied) >= 4) { seat.Status = SeatStatus.Empty; } } return(ToString()); }