Exemplo n.º 1
0
        private static List <Bag> ConvertToBags(string input)
        {
            return(input
                   .SplitIntoLines()
                   .Select(line =>
            {
                var matched =
                    RegexUtils.Deserialize <BagMatch>(line, @"^(?<Id>\w+ \w+) bags contain (?<MoreBags>.*)\.$");
                var bag = new Bag(matched.Id);

                foreach (var subbag in RegexUtils.DeserializeMany <MoreBagsMatch>(matched.MoreBags,
                                                                                  @"(?<Count>\d+) (?<Id>\w+ \w+) bag"))
                {
                    bag.Add(subbag.Id, subbag.Count);
                }

                return bag;
            })
                   .ToList());
        }
Exemplo n.º 2
0
 private static Instruction[] ConvertInput(string input)
 {
     return(RegexUtils.DeserializeMany <Instruction>(input, @"(?<Operation>\w+) (?<Argument>[+-]\d+)")
            .ToArray());
 }
Exemplo n.º 3
0
 private static List <List <MathToken> > ConvertInput(string input)
 {
     return(input.SplitIntoLines()
            .Select(line => RegexUtils.DeserializeMany <MathToken>(line, @"(?<Number>\d+)|(?<Operator>[+*()])"))
            .ToList());
 }