Exemple #1
0
        internal static void Solve_Part1()
        {
            Console.WriteLine("Solving Day 01, Part 1...");

              var directions = System.IO.File.ReadAllText("01.txt").Split(',');
              var pt = new Point();

              foreach (var direction in directions)
              {
            if (string.IsNullOrWhiteSpace(direction))
              continue;

            pt.Walk(
              direction.Trim().Substring(0, 1),
              int.Parse(direction.Trim().Substring(1)),
              false);
              }

              Console.WriteLine($"You are at {pt}; which is {Math.Abs(pt.X) + Math.Abs(pt.Y)} blocks away...");

              // correct:
              //   279

              return;
        }
Exemple #2
0
        internal static void Solve_Part2()
        {
            Console.WriteLine("Solving Day 01, Part 2...");

              var directions = System.IO.File.ReadAllText("01.txt").Split(',');
              var pt = new Point();
              var hist = new List<string>();

              foreach (var direction in directions)
              {
            if (string.IsNullOrWhiteSpace(direction))
              continue;

            var beenThere = pt.Walk(
              direction.Trim().Substring(0, 1),
              int.Parse(direction.Trim().Substring(1)),
              true);
            if (beenThere)
              break;
              }

              // wrong:
              //   297 (high)
              // correct:
              //   163

              return;
        }