about summary refs log tree commit diff
path: root/Day11.cs
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2020-12-02 00:36:24 -0500
committerBen Harris <ben@tilde.team>2020-12-02 00:36:24 -0500
commit36bb28af87e81a9b3cab1abd79d11106cd610f6c (patch)
treed4648bba69ceb5e20753acf54df51d74cff4731b /Day11.cs
parent00c3b51b897c33210679de546eebcd9ec75247a1 (diff)
update gitignore and run resharper cleanup
Diffstat (limited to 'Day11.cs')
-rw-r--r--Day11.cs73
1 files changed, 48 insertions, 25 deletions
diff --git a/Day11.cs b/Day11.cs
index 4fc323b..647be9a 100644
--- a/Day11.cs
+++ b/Day11.cs
@@ -1,48 +1,62 @@
-using aoc2019.lib;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using aoc2019.lib;
 
 namespace aoc2019
 {
     internal sealed class Day11 : Day
     {
-        public override int DayNumber => 11;
-
         private readonly IntCodeVM vm;
-        private long x, y;
         private Direction heading;
+        private long x, y;
 
         public Day11()
         {
             vm = new IntCodeVM(Input.First());
         }
 
-        enum Direction
-        {
-            Up, Down, Left, Right
-        }
+        public override int DayNumber => 11;
 
         private void Move()
         {
             switch (heading)
             {
-                case Direction.Up: y++; break;
-                case Direction.Down: y--; break;
-                case Direction.Left: x--; break;
-                case Direction.Right: x++; break;
-            };
+                case Direction.Up:
+                    y++;
+                    break;
+                case Direction.Down:
+                    y--;
+                    break;
+                case Direction.Left:
+                    x--;
+                    break;
+                case Direction.Right:
+                    x++;
+                    break;
+            }
+
+            ;
         }
 
         private void Turn(long direction)
         {
             switch (heading)
             {
-                case Direction.Up: heading = direction == 0 ? Direction.Left : Direction.Right; break;
-                case Direction.Down: heading = direction == 0 ? Direction.Right : Direction.Left; break;
-                case Direction.Left: heading = direction == 0 ? Direction.Down : Direction.Up; break;
-                case Direction.Right: heading = direction == 0 ? Direction.Up : Direction.Down; break;
+                case Direction.Up:
+                    heading = direction == 0 ? Direction.Left : Direction.Right;
+                    break;
+                case Direction.Down:
+                    heading = direction == 0 ? Direction.Right : Direction.Left;
+                    break;
+                case Direction.Left:
+                    heading = direction == 0 ? Direction.Down : Direction.Up;
+                    break;
+                case Direction.Right:
+                    heading = direction == 0 ? Direction.Up : Direction.Down;
+                    break;
             }
+
             Move();
         }
 
@@ -51,7 +65,8 @@ namespace aoc2019
             var map = new Dictionary<(long, long), long>();
             vm.Reset();
             heading = Direction.Up;
-            x = 0; y = 0;
+            x = 0;
+            y = 0;
             map[(x, y)] = initialVal;
 
             var haltType = IntCodeVM.HaltType.Waiting;
@@ -73,19 +88,27 @@ namespace aoc2019
         public override string Part2()
         {
             var map = PaintShip(1);
-            int minX = (int)map.Keys.Select(x => x.x).Min();
-            int maxX = (int)map.Keys.Select(x => x.x).Max();
-            int minY = (int)map.Keys.Select(x => x.y).Min();
-            int maxY = (int)map.Keys.Select(x => x.y).Max();
+            var minX = (int) map.Keys.Select(x => x.x).Min();
+            var maxX = (int) map.Keys.Select(x => x.x).Max();
+            var minY = (int) map.Keys.Select(x => x.y).Min();
+            var maxY = (int) map.Keys.Select(x => x.y).Max();
 
             return Enumerable.Range(minY, maxY - minY + 1)
                 .Select(y =>
                     Enumerable.Range(minX, maxX - minX + 1)
-                    .Select(x => map.GetValueOrDefault((x, y)) == 0 ? ' ' : '#')
-                    .ToDelimitedString()
+                        .Select(x => map.GetValueOrDefault((x, y)) == 0 ? ' ' : '#')
+                        .ToDelimitedString()
                 )
                 .Reverse()
                 .ToDelimitedString(Environment.NewLine);
         }
+
+        private enum Direction
+        {
+            Up,
+            Down,
+            Left,
+            Right
+        }
     }
-}
+}
\ No newline at end of file