public void Part1_Example_Step1() { // Arrange var input = Day11.ParseFloor(@"L.LL.LL.LL LLLLLLL.LL L.L.L..L.. LLLL.LL.LL L.LL.LL.LL L.LLLLL.LL ..L.L..... LLLLLLLLLL L.LLLLLL.L L.LLLLL.LL"); var output = new SeatState[input.GetLength(0), input.GetLength(1)]; // Act subject.Step1(input, output); // Assert var expectedOutput = Day11.ParseFloor(@"#.##.##.## #######.## #.#.#..#.. ####.##.## #.##.##.## #.#####.## ..#.#..... ########## #.######.# #.#####.##"); output.Should().BeEquivalentTo(expectedOutput); }
public Ferry(List <string> Data) { var width = Data[0].Length; var waitingArea = new SeatState[Data.Count, width]; for (int x = 0; x < Data.Count; x++) { for (int y = 0; y < width; y++) { if (Data[x][y] == '#') { waitingArea[x, y] = SeatState.Occupied; } if (Data[x][y] == 'L') { waitingArea[x, y] = SeatState.Open; } if (Data[x][y] == '.') { waitingArea[x, y] = SeatState.Ground; } } } WaitingArea = waitingArea; }
private SeatState ApplyRuleTwo(SeatState state, int row, int column) { var newState = state; List <SeatState> adjacentSeats; switch (state) { case SeatState.Empty: adjacentSeats = GetVisibleAdjacentOccupiedSeats(row, column); if (!adjacentSeats.Any()) { newState = SeatState.Occupied; } break; case SeatState.Occupied: adjacentSeats = GetVisibleAdjacentOccupiedSeats(row, column); if (adjacentSeats.Count() >= 5) { newState = SeatState.Empty; } break; } return(newState); }
public bool AddTicketToDB(Film film, int customerID, int timeSessionFilm, SeatState seatState) { //get time session BookingTicket result = new BookingTicket(); try { var resultTimeSession = _timeSessionRepository.GetSingleById(timeSessionFilm); //ticket detail result.BookingTicketPrefix = "TIC"; result.BookingTicketFilmID = film.FilmID; result.BookingTicketPrice = 0; result.BookingTicketRoomID = 1; result.BookingPaymentDate = DateTime.Now; result.BookingTicketStatusID = StatusCommonConstrants.ACTIVE; result.BookingTicketTimeDetail = resultTimeSession.TimeDetail; result.CustomerID = customerID; //state seat detail resultTimeSession.SeatTableState = BookingTimeHelpers.ConvertBookingSessionToJson(seatState); //add _bookingTicketRepository.Add(result); _unitOfWork.Commit(); return(true); } catch (Exception ex) { _unitOfWork.RollbackTran(); return(false); } return(false); }
public void Run2() { var floor = ParseFloor(); var nextIteration = new SeatState[floor.GetLength(0), floor.GetLength(1)]; var iterations = 0; while (true) { var changes = Step2(floor, nextIteration); // Seating pattern converged if (changes == 0) { break; } // The new iteration will be the floor for the next iteraton // the old array will be the working place for the next iteration var temp = floor; floor = nextIteration; nextIteration = temp; iterations++; } Iterations = iterations; OccupiedSeats = CountOccupiedSeats(floor); }
public int IncrementRoundV2() { var newSeats = Seats; int changes = 0; for (int row = 0; row < _rowCount; row++) { for (int col = 0; col < _colCount; col++) { SeatState state = _seats[row, col]; if (state == SeatState.Floor) { continue; } int occupiedNearby = GetVisibleSeats(row, col).Count(s => s == SeatState.Occupied); if (state == SeatState.Empty && occupiedNearby == 0) { newSeats[row, col] = SeatState.Occupied; changes++; } else if (state == SeatState.Occupied && occupiedNearby >= 5) { newSeats[row, col] = SeatState.Empty; changes++; } } } _seats = newSeats; return(changes); }
private void SetSeatState(SeatState state, params int[] indices) { foreach (var index in indices) { _seatData[index].State = state; } }
public Seat(char state) { switch (state) { case '.': this.state = SeatState.NoSeat; break; case 'L': this.state = SeatState.Empty; break; case '#': this.state = SeatState.Occupied; break; } this.nextState = this.state; this.initialState = this.state; neighbours = new Seat[8]; for (int n = 0; n < 8; n++) { neighbours[n] = new Seat(SeatState.NoSeat); } pt2Neighbours = new Seat[8]; for (int n = 0; n < 8; n++) { pt2Neighbours[n] = new Seat(SeatState.NoSeat); } }
public static SeatState[,] ParseFloor(string input) { input = input.Replace("\r", ""); var lines = input.Split('\n'); int width = lines[0].Length; int height = lines.Length; var result = new SeatState[width, height]; for (var i = 0; i < lines.Length; i++) { for (int j = 0; j < lines[i].Length; j++) { result[j, i] = lines[i][j] switch { '.' => SeatState.Floor, 'L' => SeatState.Empty, '#' => SeatState.Occupied, var x => throw new Exception($"Unknown seat type '{x}'") }; } } return(result); }
public void SetState(int x, int y, SeatState state) { if (x >= 0 && x < width && y >= 0 && y < height) { seats[y, x].State = state; } }
private SeatState ApplyRule(SeatState state, int row, int column) { var newState = state; List <SeatState> adjacentSeats; switch (state) { case SeatState.Empty: adjacentSeats = GetAdjacentSeats(row, column); if (adjacentSeats.TrueForAll(s => s != SeatState.Occupied)) { newState = SeatState.Occupied; } break; case SeatState.Occupied: adjacentSeats = GetAdjacentSeats(row, column); if (adjacentSeats.Count(s => s == SeatState.Occupied) >= 4) { newState = SeatState.Empty; } break; } return(newState); }
public int SetTMEventSeatState(int tmeventSeatId, SeatState state) { TMEventSeatDto tmeventSeatDto = _tmeventSeatService.GetTMEventSeat(tmeventSeatId); tmeventSeatDto.State = state; return(_tmeventSeatService.UpdateTMEventSeat(tmeventSeatDto)); }
public bool Flip() { var changes = this.state != this.nextState; this.state = this.nextState; return(changes); }
public Seat(int uniqueSeatPlace) { this.uniqueSeatPlace = uniqueSeatPlace; this.state = SeatState.Free; ReadyCommands(); ReadyRecovers(); }
public LobbyPlayerState(ulong clientId, string name, int playerNum, SeatState state, int seatIdx = -1, float lastChangeTime = 0) { ClientId = clientId; PlayerName = name; PlayerNum = playerNum; SeatState = state; SeatIdx = seatIdx; LastChangeTime = lastChangeTime; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null || LobbyViewModel.Instance.CurrentSeat == null) { return(false); } SeatState state = (SeatState)value; SeatState currentState = LobbyViewModel.Instance.CurrentSeat.State; return(currentState == SeatState.Host && state != SeatState.Host && state != SeatState.Gaming); }
public CinemaHall(int rowsCount, int colsCount) { _seats = new SeatState[rowsCount][]; for (int i = 0; i < rowsCount; i++) { _seats[i] = new SeatState[colsCount]; for (int k = 0; k < colsCount; k++) { _seats[i][k] = SeatState.Free; } } }
public Seat(char state) { switch (state) { case '.': this.State = SeatState.Floor; break; case 'L': this.State = SeatState.Empty; break; } }
private static SeatState[,] GetSeatLayout(List <SeatDto> seatData, List <SeatDto> desiredSeats) { var maxColumn = Math.Max(seatData.Max(s => s.LayoutColumn), desiredSeats.Max(s => s.LayoutColumn)) + 1; var maxRow = Math.Max(seatData.Max(s => s.LayoutColumn), desiredSeats.Max(s => s.LayoutColumn)) + 1; var layout = new SeatState[maxRow, maxColumn]; foreach (var seat in seatData) { layout[seat.LayoutRow, seat.LayoutColumn] = seat.State; } return(layout); }
private char GetCharFromSeat(SeatState c) { switch (c) { case SeatState.Empty: return('L'); case SeatState.Occupied: return('#'); case SeatState.Floor: return('.'); default: return(' '); } }
public static async Task Run() { if (await Load() is not SeatState[,] seats) { return; } int height = seats.GetLength(0); int width = seats.GetLength(1); var updatedSeats = new SeatState[height, width]; bool changed; do { changed = false; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { updatedSeats[i, j] = ( Offsets.Count(off => IsOccupiedAlong(seats, j, i, off.x, off.y)), seats[i, j] ) switch { (0, SeatState.Empty) => SeatState.Occupied, (>= 5, SeatState.Occupied) => SeatState.Empty, (_, SeatState state) => state }; if (updatedSeats[i, j] != seats[i, j]) { changed = true; } } } (seats, updatedSeats) = (updatedSeats, seats); } while (changed); Console.WriteLine($"Number of occupied seats: {seats.Flatten().Count(s => s == SeatState.Occupied)}"); }
public void CalculateNextState(bool isPart2) { var numOcc = isPart2 ? 5 : 4; var activeNB = isPart2 ? pt2Neighbours : neighbours; if (state == SeatState.Empty) { if (activeNB.Where(nb => nb.state == SeatState.Occupied).Count() == 0) { nextState = SeatState.Occupied; } } else if (state == SeatState.Occupied) { if (activeNB.Where(nb => nb.state == SeatState.Occupied).Count() >= numOcc) { nextState = SeatState.Empty; } } }
public void Part1_Example_Step2() { // Arrange var input = Day11.ParseFloor(@"#.##.##.## #######.## #.#.#..#.. ####.##.## #.##.##.## #.#####.## ..#.#..... ########## #.######.# #.#####.##"); logger.LogInformation("Input:"); input.PrintField(logger); var output = new SeatState[input.GetLength(0), input.GetLength(1)]; // Act subject.Step1(input, output); logger.LogInformation("\n\nOutput:"); output.PrintField(logger); // Assert var expectedOutput = Day11.ParseFloor(@"#.LL.L#.## #LLLLLL.L# L.L.L..L.. #LLL.LL.L# #.LL.LL.LL #.LLLL#.## ..L.L..... #LLLLLLLL# #.LLLLLL.L #.#LLLL.##"); logger.LogInformation("\n\nExpectedOutput:"); expectedOutput.PrintField(logger); output.Should().BeEquivalentTo(expectedOutput); }
public static Seating Next(Seating seating, int maxDistance, int maxNeighours) { var seats = new SeatState[seating.Rows, seating.Columns]; for (var row = 0; row < seating.Rows; row++) { for (var column = 0; column < seating.Columns; column++) { var neighboursOccupied = seating.NeighboursInState(row, column, SeatState.Occupied, maxDistance); var state = seating.Seats[row, column]; if (state == SeatState.Occupied && neighboursOccupied >= maxNeighours) { state = SeatState.Empty; } else if (state == SeatState.Empty && neighboursOccupied == 0) { state = SeatState.Occupied; } seats.SetValue(state, row, column); } } return(new Seating(seats)); }
public static Seat ToEntity(this Messages.Dtos.Seat seat, SeatState seatState) { return(new Seat(seat.Row, seat.Number, seatState)); }
private void SetSeat(SeatState newState, int row, int column) { _seatLayout[row, column] = newState; }
/// <summary> /// Seat Constructor /// </summary> public CSeat() { customerId = 0; sState = SeatState.Available; }
public static IList <Seat> ToEntity(this IEnumerable <Messages.Dtos.Seat> dtos, SeatState seatState) { return(dtos.Select(x => new Seat(x.Row, x.Number, seatState)).ToList()); }
public void SeatStateChanged(int seatNumber, SeatState oldState, SeatState newState) { if (SeatChanged != null) SeatChanged(seatNumber, oldState, newState); }
public Seat(string row, int number, SeatState state) { Row = row; Number = number; State = state; }
public Seat(SeatState inState) { state = inState; }
private async Task AssertFlightState(Guid flightId, string seatId, SeatState expected) { var flight = await flightsClient.GetFlightAsync(flightId); flight.Seats.Single(x => x.Id == seatId).State.Should().Be(expected); }
private void BuySeatsHandler(BuySeats obj) { state = SeatState.Bought; }
private void ReserveSeatsHandler(ReserveSeats message) { state = SeatState.TemporalyReserved; }