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>
|
/// </summary>
|
||||||
public sealed class Day13 : Day
|
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;
|
private readonly List<(char axis, int index)> _folds;
|
||||||
|
|
||||||
public Day13() : base(13, "Transparent Origami")
|
public Day13() : base(13, "Transparent Origami")
|
||||||
{
|
{
|
||||||
var s = Input.Split("").ToList();
|
var s = Input.Split("").ToList();
|
||||||
|
|
||||||
_grid = s[0].Select(p =>
|
_dots = s[0].Select(p =>
|
||||||
{
|
{
|
||||||
var i = p.Split(',', 2).Select(int.Parse).ToList();
|
var i = p.Split(',', 2).Select(int.Parse).ToList();
|
||||||
return (i[0], i[1]);
|
return (i[0], i[1]);
|
||||||
|
@ -34,15 +34,12 @@ public sealed class Day13 : Day
|
||||||
switch (axis)
|
switch (axis)
|
||||||
{
|
{
|
||||||
case 'x':
|
case 'x':
|
||||||
foreach (var (x, y) in grid)
|
foreach (var (x, y) in grid) result.Add((x > at ? 2 * at - x : x, y));
|
||||||
result.Add((x > at ? 2 * at - x : x, y));
|
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
foreach (var (x, y) in grid)
|
foreach (var (x, y) in grid) result.Add((x, y > at ? 2 * at - y : y));
|
||||||
result.Add((x, y > at ? 2 * at - y : y));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default: throw new ArgumentException("invalid fold axis", nameof(axis));
|
||||||
throw new ArgumentException("invalid fold axis", nameof(axis));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.Distinct().ToList();
|
return result.Distinct().ToList();
|
||||||
|
@ -50,14 +47,14 @@ public sealed class Day13 : Day
|
||||||
|
|
||||||
private string PrintGrid()
|
private string PrintGrid()
|
||||||
{
|
{
|
||||||
var xMax = _grid.Max(g => g.x);
|
var xMax = _dots.Max(g => g.x);
|
||||||
var yMax = _grid.Max(g => g.y);
|
var yMax = _dots.Max(g => g.y);
|
||||||
var s = new StringBuilder();
|
var s = new StringBuilder();
|
||||||
|
|
||||||
for (var y = 0; y <= yMax; y++)
|
for (var y = 0; y <= yMax; y++)
|
||||||
{
|
{
|
||||||
for (var x = 0; x <= xMax; x++)
|
for (var x = 0; x <= xMax; x++)
|
||||||
s.Append(_grid.Contains((x, y)) ? "█" : "▒");
|
s.Append(_dots.Contains((x, y)) ? "█" : "▒");
|
||||||
|
|
||||||
s.AppendLine();
|
s.AppendLine();
|
||||||
}
|
}
|
||||||
|
@ -65,18 +62,14 @@ public sealed class Day13 : Day
|
||||||
return s.ToString();
|
return s.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override object Part1()
|
public override object Part1() =>
|
||||||
{
|
DoFold(_dots, _folds[0].axis, _folds[0].index).Count;
|
||||||
var (axis, at) = _folds[0];
|
|
||||||
var foldedOnce = DoFold(_grid, axis, at);
|
|
||||||
return foldedOnce.Count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object Part2()
|
public override object Part2()
|
||||||
{
|
{
|
||||||
foreach (var (axis, at) in _folds)
|
foreach (var (axis, at) in _folds)
|
||||||
_grid = DoFold(_grid, axis, at);
|
_dots = DoFold(_dots, axis, at);
|
||||||
|
|
||||||
return Environment.NewLine + PrintGrid();
|
return Environment.NewLine + PrintGrid();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue