Dag 5
Jag tragglar vidare i C# .Net 5 med mina lÄnga lösningar
public static string Run1(bool test = false)
{
int _Day = 5;
string[] inputData = InputData.GetInputArrString(_Day, test);
List<UInt16> AllSeats = new List<UInt16>();
for (UInt16 row = 0; row < 128; row++)
{
for (UInt16 col = 0; col < 8; col++)
{
UInt16 _seatId = (UInt16)((row * (UInt16)8) + col);
AllSeats.Add(_seatId);
}
}
UInt16 highestSeatId = 0;
for (int i = 0; i < inputData.Length; i++)
{
string bp = inputData[i];
bp = bp.Replace("B", "1");
bp = bp.Replace("F", "0");
bp = bp.Replace("R", "1");
bp = bp.Replace("L", "0");
UInt16 SeatId = Convert.ToUInt16(bp, 2);
if (SeatId>highestSeatId)
{
highestSeatId = SeatId;
}
AllSeats.Remove(SeatId);
}
UInt16 foundId = 0;
foreach (UInt16 item in AllSeats)
{
if (!AllSeats.Contains((UInt16)(item+(UInt16)1)) && !AllSeats.Contains((UInt16)(item - (UInt16)1)))
{
foundId = item;
}
}
return highestSeatId.ToString() + " : " +foundId.ToString();
}