Пример #1
0
 protected bool Equals(Moon other)
 {
     return(this.X == other.X &&
            this.Y == other.Y &&
            this.Z == other.Z &&
            this.VelocityX == other.VelocityX &&
            this.VelocityY == other.VelocityY &&
            this.VelocityZ == other.VelocityZ);
 }
Пример #2
0
        private static Moon[] ParseMoons(string[] input)
        {
            var parseRegex = new Regex("<x=(?<x>-?\\d+), y=(?<y>-?\\d+), z=(?<z>-?\\d+)");
            var moons      = input.Select(l =>
            {
                var match  = parseRegex.Match(l).Groups;
                var result = new Moon()
                {
                    X = int.Parse(match["x"].Value),
                    Y = int.Parse(match["y"].Value),
                    Z = int.Parse(match["z"].Value)
                };
                return(result);
            }).ToArray();

            return(moons);
        }
Пример #3
0
        private void ApplyGravity(Moon moon)
        {
            VelX = moon.PosX switch
            {
                var refX when PosX <refX => ++ VelX,
                                    var refX when PosX> refX => -- VelX,
                                                        _ => VelX
            };

            VelY = moon.PosY switch
            {
                var refY when PosY <refY => ++ VelY,
                                    var refY when PosY> refY => -- VelY,
                                                        _ => VelY
            };

            VelZ = moon.PosZ switch
            {
                var refZ when PosZ <refZ => ++ VelZ,
                                    var refZ when PosZ> refZ => -- VelZ,
                                                        _ => VelZ
            };
        }
Пример #4
0
 public MoonRelationship(Moon a, Moon b)
 {
     this.A = a;
     this.B = b;
 }