public void Example1() { var input = "939|7,13,x,x,59,x,31,19".Replace("|", Environment.NewLine); var busInfo = BusScheduleParser.Parse(input); var canDepart = false; var departTime = 0L; Bus bus = null; for (var timeStamp = busInfo.EarliestDepartureTime; canDepart == false; timeStamp++) { foreach (var schedule in busInfo.Schedules) { canDepart = schedule.DoesDepartAt(timeStamp); if (!canDepart) { continue; } bus = schedule; departTime = timeStamp; break; } } var sum = (departTime - busInfo.EarliestDepartureTime) * bus.Id; Assert.Equal(295, sum); }
public void SolvePuzzle1() { var input = new FileReader() .GetResource("AdventOfCode2020.Tests.Day13.PuzzleInput.txt"); var busInfo = BusScheduleParser.Parse(input); var canDepart = false; var departTime = 0L; Bus bus = null; for (var timeStamp = busInfo.EarliestDepartureTime; canDepart == false; timeStamp++) { foreach (var schedule in busInfo.Schedules) { canDepart = schedule.DoesDepartAt(timeStamp); if (!canDepart) { continue; } bus = schedule; departTime = timeStamp; break; } } var sum = (departTime - busInfo.EarliestDepartureTime) * bus.Id; Assert.Equal(333, sum); }
public void ParserTest() { var input = "939|7,13,x,x,59,x,31,19".Replace("|", Environment.NewLine); var busInfo = BusScheduleParser.Parse(input); Assert.Equal(939, busInfo.EarliestDepartureTime); Assert.Equal(5, busInfo.Schedules.Count); }