示例#1
0
    bool ProveFor(string test)
    {
        var lines   = File.ReadAllLines(test, Encoding.UTF8);
        var bestLoc = lines[0].Split(",").Select(x => int.Parse(x));
        var count   = int.Parse(lines[1]);
        var map     = lines.Skip(2).ToArray();
        var starMap = StarMap.Parse(map);

        starMap.FindBestAsteroid();

        var bestStar = starMap.bestStar;

        return(bestStar.X == bestLoc.ElementAt(0) && bestStar.Y == bestLoc.ElementAt(1) && starMap.maxStarsVisible == count);
    }
示例#2
0
 public string Solve(bool isA)
 {
     if (isA)
     {
         var lines   = File.ReadAllLines(Input, Encoding.UTF8);
         var starMap = StarMap.Parse(lines);
         starMap.FindBestAsteroid();
         Console.WriteLine($"Best star is {starMap.bestStar} with {starMap.maxStarsVisible} visible.");
         return(starMap.maxStarsVisible.ToString());
     }
     else
     {
         return(SolveB(Input, new Point(37, 25)).ToString());
     }
 }
示例#3
0
    public int SolveB(string input, Point station)
    {
        var lines   = File.ReadAllLines(input, Encoding.UTF8);
        var starMap = StarMap.Parse(lines);

        // Convert all the stars to polar coords
        var polar = new PolarStarMap(starMap, station);

        var             destroyed = new List <Point>();
        Func <int, int> increment = (index) =>
        {
            index++;
            if (index >= polar.stars.Count)
            {
                index = 0;
            }
            return(index);
        };
        Point?last = null;

        for (int index = 0; destroyed.Count < 200 && destroyed.Count < polar.stars.Count; index = increment(index))
        {
            if (index == 0)
            {
                last = null;
            }
            var  consider  = polar.stars[index];
            bool sameAngle = last.HasValue && Helper.sameAs(Helper.theta(last.Value, station), Helper.theta(consider, station));
            bool valid     = !destroyed.Contains(polar.stars[index]) && !sameAngle;
            if (valid)
            {
                destroyed.Add(consider);
                last = consider;
                // Console.WriteLine(consider);
            }
        }

        var asteroid = last.Value;

        return((int)Math.Round(asteroid.X * 100 + asteroid.Y));
    }