Esempio n. 1
0
        public long GetAnswer()
        {
            _slope = DataGetter.GetData();
            long answer     = 1;
            var  traversals = GetTraversals();

            foreach (var traversal in traversals)
            {
                var currentRow = 0;
                var currentCol = 0;
                var treesHit   = 0;

                while (currentRow < _slope.Rows.Count)
                {
                    if (IsATree(currentRow, currentCol))
                    {
                        treesHit++;
                    }

                    currentCol += traversal.Right;
                    currentRow += traversal.Down;
                }

                answer = answer * treesHit;
            }

            return(answer);
        }
Esempio n. 2
0
        public static SlopeModel GetData()
        {
            var result = new SlopeModel();

            using (var sr = new StreamReader("../../../DayThree/input.txt"))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    var row = new SlopeRow();
                    row.Location = line.Select(a => a.ToString()).ToList();
                    result.Rows.Add(row);
                }
            }

            return(result);
        }