예제 #1
0
        public Day3Input Parse(string[] values)
        {
            Line1 = values.First().Split(',').Select(c => new Instruction
            {
                Direction = c.First(),
                Count     = int.Parse(c.Substring(1))
            }).ToList();
            Line2 = values.ElementAt(1).Split(',').Select(c => new Instruction
            {
                Direction = c.First(),
                Count     = int.Parse(c.Substring(1))
            }).ToList();

            MaxLeft  = Line1.Where(c => c.Direction == 'L').Sum(c => c.Count);
            MaxRight = Line1.Where(c => c.Direction == 'R').Sum(c => c.Count);
            MaxUp    = Line1.Where(c => c.Direction == 'U').Sum(c => c.Count);
            MaxDown  = Line1.Where(c => c.Direction == 'D').Sum(c => c.Count);

            MaxLeft  = Math.Max(MaxLeft, Line2.Where(c => c.Direction == 'L').Sum(c => c.Count));
            MaxRight = Math.Max(MaxRight, Line2.Where(c => c.Direction == 'R').Sum(c => c.Count));
            MaxUp    = Math.Max(MaxUp, Line2.Where(c => c.Direction == 'U').Sum(c => c.Count));
            MaxDown  = Math.Max(MaxDown, Line2.Where(c => c.Direction == 'D').Sum(c => c.Count));

            return(this);
        }