tidy up a bit
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
5adf034e6e
commit
7273a296be
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue