static int CountTrees(Map map, Slope slope) { var point = new Point(0, 0); var trees = 0; while (true) { point = point with { X = point.X + slope.Right, Y = point.Y + slope.Down }; var field = map.GetFieldType(point); if (!field.HasValue) { break; } else if (field.Value == FieldType.Tree) { trees++; } } return(trees); } }
public int CountTrees(Slope slope) { var x = 0; var y = 0; var trees = 0; while (y < _lines.Count) { var current = _lines[y][x % LINE_LENGTH]; if (current == '#') { trees++; } x += slope.X; y -= slope.Y; } return(trees); }