about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2021-12-13 01:38:11 -0500
committerBen Harris <ben@tilde.team>2021-12-13 01:38:46 -0500
commit7273a296beecbdce7b25fbc5bdf6fb793eba148a (patch)
tree3683ca4be70ab0f45a52d8b858cd0be7ac45b85b
parent5adf034e6ea7e99e668174d6db227d1da01798bb (diff)
tidy up a bit
-rw-r--r--aoc2021/Day13.cs31
1 files changed, 12 insertions, 19 deletions
diff --git a/aoc2021/Day13.cs b/aoc2021/Day13.cs
index 1ad9016..7c35bb5 100644
--- a/aoc2021/Day13.cs
+++ b/aoc2021/Day13.cs
@@ -7,14 +7,14 @@ namespace aoc2021;
 /// </summary>
 public sealed class Day13 : Day
 {
-    private List<(int x, int y)> _grid;
+    private List<(int x, int y)> _dots;
     private readonly List<(char axis, int index)> _folds;
     
     public Day13() : base(13, "Transparent Origami")
     {
         var s = Input.Split("").ToList();
         
-        _grid = s[0].Select(p =>
+        _dots = s[0].Select(p =>
         {
             var i = p.Split(',', 2).Select(int.Parse).ToList();
             return (i[0], i[1]);
@@ -34,15 +34,12 @@ public sealed class Day13 : Day
         switch (axis)
         {
             case 'x':
-                foreach (var (x, y) in grid)
-                    result.Add((x > at ? 2 * at - x : x, y));
+                foreach (var (x, y) in grid) result.Add((x > at ? 2 * at - x : x, y));
                 break;
             case 'y':
-                foreach (var (x, y) in grid)
-                    result.Add((x, y > at ? 2 * at - y : y));
+                foreach (var (x, y) in grid) result.Add((x, y > at ? 2 * at - y : y));
                 break;
-            default:
-                throw new ArgumentException("invalid fold axis", nameof(axis));
+            default: throw new ArgumentException("invalid fold axis", nameof(axis));
         }
 
         return result.Distinct().ToList();
@@ -50,14 +47,14 @@ public sealed class Day13 : Day
 
     private string PrintGrid()
     {
-        var xMax = _grid.Max(g => g.x);
-        var yMax = _grid.Max(g => g.y);
+        var xMax = _dots.Max(g => g.x);
+        var yMax = _dots.Max(g => g.y);
         var s = new StringBuilder();
 
         for (var y = 0; y <= yMax; y++)
         {
             for (var x = 0; x <= xMax; x++)
-                s.Append(_grid.Contains((x, y)) ? "█" : "▒");
+                s.Append(_dots.Contains((x, y)) ? "█" : "▒");
 
             s.AppendLine();
         }
@@ -65,18 +62,14 @@ public sealed class Day13 : Day
         return s.ToString();
     }
 
-    public override object Part1()
-    {
-        var (axis, at) = _folds[0];
-        var foldedOnce = DoFold(_grid, axis, at);
-        return foldedOnce.Count;
-    }
+    public override object Part1() =>
+        DoFold(_dots, _folds[0].axis, _folds[0].index).Count;
 
     public override object Part2()
     {
         foreach (var (axis, at) in _folds)
-            _grid = DoFold(_grid, axis, at);
+            _dots = DoFold(_dots, axis, at);
 
         return Environment.NewLine + PrintGrid();
     }
-}
+}
\ No newline at end of file