Example #1
0
        static Res Algoritm_1(Train train)
        {
            People people     = new People(train);
            Wagon  startWagon = people.CurrentWagon;

            startWagon.OnLight();
            people.GoBack();
            people.CurrentWagon.OffLight();
            people.GoForward();

            int countWagons = Tuda_1(people);

            while (true)
            {
                if (!startWagon.Light)
                {
                    return(new Res()
                    {
                        CountWagons = countWagons - 1, TotalWagonsPassed = people.TotalWagonsPassed
                    });
                }

                countWagons = Suda_1(people, countWagons);

                if (!startWagon.Light)
                {
                    return(new Res()
                    {
                        CountWagons = countWagons - 1, TotalWagonsPassed = people.TotalWagonsPassed
                    });
                }

                countWagons = Tuda_1(people, countWagons);
            }
        }
Example #2
0
        static Res Algoritm_2(Train train)
        {
            People people     = new People(train);
            Wagon  startWagon = people.CurrentWagon;

            startWagon.OnLight();
            people.GoBack();
            people.CurrentWagon.OffLight();
            people.GoForward();


            Tuda_2(people);
            while (true)
            {
                if (TudaCheckLightOff(people, people.Position - 2))
                {
                    int potencialCountWagon = (people.Position + 1) / 2;

                    // проверка света стартвого вагона бегом назад
                    while (people.Position != 0)
                    {
                        people.GoBack();
                    }

                    if (people.CurrentWagon.Light)
                    {
                        // не прошла
                        Tuda_2(people);
                    }
                    else
                    {
                        // прошла - вывод результата
                        return(new Res()
                        {
                            CountWagons = potencialCountWagon, TotalWagonsPassed = people.TotalWagonsPassed
                        });
                    }
                }
                else
                {
                    Tuda2_2(people);
                }
            }
        }