Exemplo n.º 1
0
        public int SolvePart1(IEnumerable <string> input, string bag)
        {
            LuggageProcessor graph = new LuggageProcessor();

            foreach (var line in input)
            {
                graph.ParseInput(line);
            }
            return(graph.GetBag(bag).Containers.Count());
        }
Exemplo n.º 2
0
        public int SolvePart2(IEnumerable <string> input, string bag)
        {
            LuggageProcessor graph = new LuggageProcessor();

            foreach (var line in input)
            {
                graph.ParseInput(line);
            }
            return(graph.GetBag(bag).GetAllContents().Values.Sum());
        }
Exemplo n.º 3
0
        public void AddContents(string contents, LuggageProcessor graph)
        {
            var items = contents.Split(", ");

            foreach (var item in items)
            {
                var space    = item.IndexOf(' ');
                var end      = item.IndexOf(" bag", space);
                var quantity = Int32.Parse(item.Substring(0, space));
                var bag      = graph.GetBag(item.Substring(space + 1, end - (space + 1)));
                bag.AddContainer(this);
                bag.AddContainers(Containers);
                Contents.Add(bag, quantity);
            }
        }