Exemplo n.º 1
0
        private void ParseInput(String input)
        {
            input = input.Trim() + ",";

            AuntSueNumber = Convert.ToInt32(StringOps.ParameterAfter(input, "Sue", ":").Trim());

            if (input.Contains("children"))
            {
                Children = Convert.ToInt32(StringOps.ParameterAfter(input, "children:", ",").Trim());
            }
            else
            {
                Children = -1;
            }

            if (input.Contains("cats"))
            {
                Cats = Convert.ToInt32(StringOps.ParameterAfter(input, "cats:", ",").Trim());
            }
            else
            {
                Cats = -1;
            }

            if (input.Contains("samoyeds"))
            {
                Samoyeds = Convert.ToInt32(StringOps.ParameterAfter(input, "samoyeds:", ",").Trim());
            }
            else
            {
                Samoyeds = -1;
            }

            if (input.Contains("pomeranians"))
            {
                Pomeranians = Convert.ToInt32(StringOps.ParameterAfter(input, "pomeranians:", ",").Trim());
            }
            else
            {
                Pomeranians = -1;
            }

            if (input.Contains("akitas"))
            {
                Akitas = Convert.ToInt32(StringOps.ParameterAfter(input, "akitas:", ",").Trim());
            }
            else
            {
                Akitas = -1;
            }

            if (input.Contains("vizslas"))
            {
                Vizslas = Convert.ToInt32(StringOps.ParameterAfter(input, "vizslas:", ",").Trim());
            }
            else
            {
                Vizslas = -1;
            }

            if (input.Contains("goldfish"))
            {
                Goldfish = Convert.ToInt32(StringOps.ParameterAfter(input, "goldfish:", ",").Trim());
            }
            else
            {
                Goldfish = -1;
            }

            if (input.Contains("trees"))
            {
                Trees = Convert.ToInt32(StringOps.ParameterAfter(input, "trees:", ",").Trim());
            }
            else
            {
                Trees = -1;
            }

            if (input.Contains("cars"))
            {
                Cars = Convert.ToInt32(StringOps.ParameterAfter(input, "cars:", ",").Trim());
            }
            else
            {
                Cars = -1;
            }

            if (input.Contains("perfumes"))
            {
                Perfumes = Convert.ToInt32(StringOps.ParameterAfter(input, "perfumes:", ",").Trim());
            }
            else
            {
                Perfumes = -1;
            }
        }
Exemplo n.º 2
0
 public static String SubStringPostAndPre(String input, String postDelimiter, String preDelimeter)
 {
     return(StringOps.SubStringPost(StringOps.SubStringPre(input, preDelimeter), postDelimiter));
 }
Exemplo n.º 3
0
        protected override String DoSolve(String[] input)
        {
            List <IRacingReindeerPoints> reindeerRace = new List <IRacingReindeerPoints>();

            //read the input
            foreach (String line in input)
            {
                String reindeerName = StringOps.SubStringPre(line, "can");
                int    flySpeed     = Convert.ToInt32(StringOps.SubStringPost(StringOps.SubStringPre(line, "km/s"), "fly").Trim());
                int    flyDuration  = Convert.ToInt32(StringOps.SubStringPost(StringOps.SubStringPre(line, "seconds,"), "km/s for").Trim());
                int    restDuration = Convert.ToInt32(StringOps.SubStringPost(StringOps.SubStringPre(line, "seconds."), "rest for").Trim());

                reindeerRace.Add(Factory.CreateRacingReindeerPoints(reindeerName, flySpeed, flyDuration, restDuration));
            }

            //Race!
            int currentSecond;
            int raceDurationSeconds = 2503;

            for (currentSecond = 0; currentSecond < raceDurationSeconds; currentSecond++)
            {
                foreach (IRacingReindeerPoints racingReindeer in reindeerRace)
                {
                    racingReindeer.Race1Second();
                }

                //Assign Points to the leader(s)
                //Find the most distance travelled
                int currentMaxDistance = 0;
                foreach (IRacingReindeerPoints racingReindeer in reindeerRace)
                {
                    if (racingReindeer.DistanceTravelled > currentMaxDistance)
                    {
                        currentMaxDistance = racingReindeer.DistanceTravelled;
                    }
                }

                //assign points to the reindeer with that maxdistance
                foreach (IRacingReindeerPoints racingReindeer in reindeerRace)
                {
                    if (racingReindeer.DistanceTravelled == currentMaxDistance)
                    {
                        racingReindeer.Points++;
                    }
                }
            }

            //who wins & how far have they travelled?
            int    maxPoints           = 0;
            String winningReindeerName = "";

            foreach (IRacingReindeerPoints racingReindeer in reindeerRace)
            {
                if (racingReindeer.Points > maxPoints)
                {
                    maxPoints           = racingReindeer.Points;
                    winningReindeerName = racingReindeer.Reindeer.Name;
                }
            }



            return($"{ winningReindeerName} is winning at {maxPoints} points!");
        }
Exemplo n.º 4
0
        protected override String DoSolve(String[] input)
        {
            List <IPath <String> > paths = new List <IPath <String> >();

            //read the input
            foreach (String line in input)
            {
                Int32 distance = Convert.ToInt32(StringOps.SubStringPost(line, "=").Trim());

                String ends = StringOps.SubStringPre(line, "=").Trim();

                IPath <String> path = Factory.CreatePath(StringOps.SubStringPre(ends, "to").Trim(), StringOps.SubStringPost(ends, "to").Trim(), distance);
                paths.Add(path);
            }

            IPathCollection pathCollection = Factory.CreatePathCollection(paths);

            Int32 longestPath = pathCollection.LongestDistance();

            return($"The Shortest Route is { longestPath }.");
        }