示例#1
0
 public void AddBusLine(string lineName)
 {
     if (!BusLines.Contains(lineName))
     {
         this.BusLines.Add(lineName);
     }
 }
示例#2
0
        public async Task <List <Bus> > GetBusScheduleAsync(IOptions <AppSettings> appSettings)
        {
            var busUrl = CreateBusUrl(appSettings);

            BusLines busLines = await GetBusesAsync(busUrl);

            return(CreateBusList(busLines));
        }
示例#3
0
        public void Example6()
        {
            List <string> IdStrings = new List <string> {
                "67", "7", "x", "59", "61"
            };

            BusLines buslines = new BusLines();
            long     result   = buslines.FindSequence2(IdStrings);

            Assert.AreEqual(1261476, result);
        }
示例#4
0
        public void Example3()
        {
            List <string> IdStrings = new List <string> {
                "17", "x", "13", "19"
            };

            BusLines buslines = new BusLines();
            long     result   = buslines.FindSequence2(IdStrings);

            Assert.AreEqual(3417, result);
        }
示例#5
0
        public void Example8()
        {
            List <string> IdStrings = new List <string> {
                "7", "13", "x", "x", "59", "x", "31", "19"
            };

            BusLines buslines = new BusLines();
            long     result   = buslines.FindSequence2(IdStrings);

            Assert.AreEqual(1068781, result);
        }
示例#6
0
        public void Example7()
        {
            List <string> IdStrings = new List <string> {
                "1789", "37", "47", "1889"
            };

            BusLines buslines = new BusLines();
            long     result   = buslines.FindSequence2(IdStrings);

            Assert.AreEqual(1202161486, result);
        }
示例#7
0
        public static long Problem2()
        {
            List <string> input = File.ReadAllLines("Data/Day13.txt").ToList();
            List <string> ids   = input[1].Split(",").ToList();

            BusLines busslines = new BusLines();

            long result = busslines.FindSequence2(ids);

            Console.WriteLine(result);
            return(result);
        }
示例#8
0
        public void Example2()
        {
            int earliest = 939;

            List <string> IdStrings = new List <string> {
                "7", "13", "x", "x", "59", "x", "31", "19"
            };

            BusLines buslines = new BusLines();
            long     result   = buslines.ParseAndGetAnswer(earliest, IdStrings);

            Assert.AreEqual(295, result);
        }
示例#9
0
        public static long Problem1()
        {
            List <string> input    = File.ReadAllLines("Data/Day13.txt").ToList();
            int           earliest = input[0].ToInt();
            List <string> ids      = input[1].Split(",").ToList();

            BusLines busslines = new BusLines();

            long result = busslines.ParseAndGetAnswer(earliest, ids);

            Console.WriteLine(result);
            return(result);
        }
示例#10
0
        public void Example1()
        {
            int earliest = 939;

            List <int> Ids = new List <int> {
                7, 13, 59, 31, 19
            };

            BusLines buslines = new BusLines();

            int Id = buslines.FindEarliestDepartureId(earliest, Ids);

            Assert.AreEqual(59, Id);

            long earliestDeparture = buslines.FindEarliestDeparture(earliest, Id);

            Assert.AreEqual(944, earliestDeparture);
        }
示例#11
0
        private List <Bus> CreateBusList(BusLines busLines)
        {
            List <Bus> buses = new List <Bus>();

            if (busLines.m1.Any())
            {
                buses = busLines.m1;

                if (busLines.m3?.Count() > 0)
                {
                    buses.AddRange(busLines.m3);
                }

                buses = buses.GroupBy(x => new { x.EstimatedDepartureTime, x.BusName }).Select(x => x.First()).OrderBy(b => b.EstimatedDepartureTime).ToList();
            }

            return(buses);
        }