ben
/
aoc
1
0
Fork 0

file endings?
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Ben Harris 2023-12-01 02:32:30 -05:00
parent e0699f49ee
commit 45d69702c2
7 changed files with 99 additions and 99 deletions

View File

@ -26,8 +26,8 @@ public sealed class Day08() : Day(2016, 8, "Two-Factor Authentication")
private static void DrawRectangle(char[,] screen, int width, int height)
{
for (var y = 0; y < height; y++)
for (var x = 0; x < width; x++)
screen[y, x] = '\u2588';
for (var x = 0; x < width; x++)
screen[y, x] = '\u2588';
}
private static void Coltate(char[,] screen, int index, int extent)
@ -65,8 +65,8 @@ public sealed class Day08() : Day(2016, 8, "Two-Factor Authentication")
{
var screen = new char[6, 50];
for (var y = 0; y < 6; y++)
for (var x = 0; x < 50; x++)
screen[y, x] = '\u2592';
for (var x = 0; x < 50; x++)
screen[y, x] = '\u2592';
foreach (var line in Input)
{

View File

@ -19,10 +19,10 @@ public sealed class Day01() : Day(2020, 1, "Report Repair")
public override object Part2()
{
foreach (var i in _entries!)
foreach (var j in _entries)
foreach (var k in _entries)
if (i + j + k == 2020)
return i * j * k;
foreach (var j in _entries)
foreach (var k in _entries)
if (i + j + k == 2020)
return i * j * k;
return default!;
}

View File

@ -13,23 +13,23 @@ public sealed class Day17() : Day(2020, 17, "Conway Cubes")
var input = Input.ToList();
for (var x = 0; x < 32; x++)
for (var y = 0; y < 32; y++)
for (var z = 0; z < 32; z++)
_plane[(x, y, z)] = '.';
for (var y = 0; y < 32; y++)
for (var z = 0; z < 32; z++)
_plane[(x, y, z)] = '.';
for (var x = 0; x < 32; x++)
for (var y = 0; y < 32; y++)
for (var z = 0; z < 32; z++)
for (var w = 0; w < 32; w++)
_plane4[(x, y, z, w)] = '.';
for (var y = 0; y < 32; y++)
for (var z = 0; z < 32; z++)
for (var w = 0; w < 32; w++)
_plane4[(x, y, z, w)] = '.';
for (var y = 0; y < input.Count; y++)
for (var x = 0; x < input[y].Length; x++)
_plane[(x, y, 0)] = input[y][x];
for (var x = 0; x < input[y].Length; x++)
_plane[(x, y, 0)] = input[y][x];
for (var y = 0; y < input.Count; y++)
for (var x = 0; x < input[y].Length; x++)
_plane4[(x, y, 0, 0)] = input[y][x];
for (var x = 0; x < input[y].Length; x++)
_plane4[(x, y, 0, 0)] = input[y][x];
}
private static int Neighbors(IReadOnlyDictionary<(int x, int y, int z), char> plane, int x, int y, int z)
@ -37,12 +37,12 @@ public sealed class Day17() : Day(2020, 17, "Conway Cubes")
var neighbors = 0;
foreach (var i in new[] { -1, 0, 1 })
foreach (var j in new[] { -1, 0, 1 })
foreach (var k in new[] { -1, 0, 1 })
{
if (i == 0 && j == 0 && k == 0) continue;
if (plane[((x + i) & 31, (y + j) & 31, (z + k) & 31)] == '#') neighbors++;
}
foreach (var j in new[] { -1, 0, 1 })
foreach (var k in new[] { -1, 0, 1 })
{
if (i == 0 && j == 0 && k == 0) continue;
if (plane[((x + i) & 31, (y + j) & 31, (z + k) & 31)] == '#') neighbors++;
}
return neighbors;
}
@ -53,15 +53,15 @@ public sealed class Day17() : Day(2020, 17, "Conway Cubes")
var next = new Dictionary<(int x, int y, int z), char>();
for (var z = 0; z < 32; z++)
for (var y = 0; y < 32; y++)
for (var x = 0; x < 32; x++)
{
var active = Neighbors(prev, x, y, z);
if (prev[(x, y, z)] == '#')
next[(x, y, z)] = active == 2 || active == 3 ? '#' : '.';
else
next[(x, y, z)] = active == 3 ? '#' : '.';
}
for (var y = 0; y < 32; y++)
for (var x = 0; x < 32; x++)
{
var active = Neighbors(prev, x, y, z);
if (prev[(x, y, z)] == '#')
next[(x, y, z)] = active == 2 || active == 3 ? '#' : '.';
else
next[(x, y, z)] = active == 3 ? '#' : '.';
}
return next;
}
@ -72,13 +72,13 @@ public sealed class Day17() : Day(2020, 17, "Conway Cubes")
var neighbors = 0;
foreach (var i in new[] { -1, 0, 1 })
foreach (var j in new[] { -1, 0, 1 })
foreach (var k in new[] { -1, 0, 1 })
foreach (var l in new[] { -1, 0, 1 })
{
if (i == 0 && j == 0 && k == 0 && l == 0) continue;
if (plane[((x + i) & 31, (y + j) & 31, (z + k) & 31, (w + l) & 31)] == '#') neighbors++;
}
foreach (var j in new[] { -1, 0, 1 })
foreach (var k in new[] { -1, 0, 1 })
foreach (var l in new[] { -1, 0, 1 })
{
if (i == 0 && j == 0 && k == 0 && l == 0) continue;
if (plane[((x + i) & 31, (y + j) & 31, (z + k) & 31, (w + l) & 31)] == '#') neighbors++;
}
return neighbors;
}
@ -89,16 +89,16 @@ public sealed class Day17() : Day(2020, 17, "Conway Cubes")
var next = new Dictionary<(int x, int y, int z, int w), char>();
for (var z = 0; z < 32; z++)
for (var y = 0; y < 32; y++)
for (var x = 0; x < 32; x++)
for (var w = 0; w < 32; w++)
{
var active = Neighbors4(prev, x, y, z, w);
if (prev[(x, y, z, w)] == '#')
next[(x, y, z, w)] = active == 2 || active == 3 ? '#' : '.';
else
next[(x, y, z, w)] = active == 3 ? '#' : '.';
}
for (var y = 0; y < 32; y++)
for (var x = 0; x < 32; x++)
for (var w = 0; w < 32; w++)
{
var active = Neighbors4(prev, x, y, z, w);
if (prev[(x, y, z, w)] == '#')
next[(x, y, z, w)] = active == 2 || active == 3 ? '#' : '.';
else
next[(x, y, z, w)] = active == 3 ? '#' : '.';
}
return next;
}

View File

@ -18,22 +18,22 @@ public sealed class Day11() : Day(2021, 11, "Dumbo Octopus")
// increment all octopuses
for (var row = 0; row < _octopusField.Length; row++)
for (var col = 0; col < _octopusField[row].Length; col++)
_octopusField[row][col]++;
for (var col = 0; col < _octopusField[row].Length; col++)
_octopusField[row][col]++;
// flash any that exceeded 10
for (var row = 0; row < _octopusField.Length; row++)
for (var col = 0; col < _octopusField[row].Length; col++)
if (_octopusField[row][col] == 10)
FlashAt(row, col);
for (var col = 0; col < _octopusField[row].Length; col++)
if (_octopusField[row][col] == 10)
FlashAt(row, col);
var done = true;
for (var row = 0; row < _octopusField.Length; row++)
for (var col = 0; col < _octopusField[row].Length; col++)
if (_octopusField[row][col] == -1)
_octopusField[row][col] = 0;
else
done = false;
for (var col = 0; col < _octopusField[row].Length; col++)
if (_octopusField[row][col] == -1)
_octopusField[row][col] = 0;
else
done = false;
if (_totalTurns == 100) _flashesAfter100 = _flashTally;
if (done) break;
@ -45,13 +45,13 @@ public sealed class Day11() : Day(2021, 11, "Dumbo Octopus")
_flashTally++;
_octopusField![r][c] = -1;
foreach (var rr in new[] { -1, 0, 1 }.Select(dr => dr + r))
foreach (var cc in new[] { -1, 0, 1 }.Select(dc => dc + c))
if (0 <= rr && rr < _octopusField.Length && 0 <= cc && cc < _octopusField[0].Length && _octopusField[rr][cc] != -1)
{
_octopusField[rr][cc]++;
if (_octopusField[rr][cc] >= 10)
FlashAt(rr, cc);
}
foreach (var cc in new[] { -1, 0, 1 }.Select(dc => dc + c))
if (0 <= rr && rr < _octopusField.Length && 0 <= cc && cc < _octopusField[0].Length && _octopusField[rr][cc] != -1)
{
_octopusField[rr][cc]++;
if (_octopusField[rr][cc] >= 10)
FlashAt(rr, cc);
}
}
public override object Part1() => _flashesAfter100;

View File

@ -29,22 +29,22 @@ public sealed class Day17() : Day(2021, 17, "Trick Shot")
while (xMin * (xMin + 1) / 2 < _target![0]) xMin++;
for (var x = xMin; x <= _target[1]; x++)
for (var y = _target[2]; y < Math.Abs(_target[2]); y++)
{
int xVelocity = x, yVelocity = y, xPos = 0, yPos = 0;
while (xPos <= _target[1] && yPos >= _target[2])
for (var y = _target[2]; y < Math.Abs(_target[2]); y++)
{
xPos += xVelocity;
yPos += yVelocity;
int xVelocity = x, yVelocity = y, xPos = 0, yPos = 0;
if (xPos >= _target[0] && xPos <= _target[1] && yPos >= _target[2] && yPos <= _target[3])
successfulVelocities.Add((x, y));
while (xPos <= _target[1] && yPos >= _target[2])
{
xPos += xVelocity;
yPos += yVelocity;
xVelocity = xVelocity == 0 ? 0 : xVelocity - 1;
yVelocity--;
if (xPos >= _target[0] && xPos <= _target[1] && yPos >= _target[2] && yPos <= _target[3])
successfulVelocities.Add((x, y));
xVelocity = xVelocity == 0 ? 0 : xVelocity - 1;
yVelocity--;
}
}
}
return successfulVelocities.Count;
}

View File

@ -107,10 +107,10 @@ public sealed class Day21() : Day(2021, 21, "Dirac Dice")
public override object Part2()
{
for (var x = 1; x <= 3; x++)
for (var y = 1; y <= 3; y++)
for (var z = 1; z <= 3; z++)
_possibleRollOutComes[x + y + z] =
_possibleRollOutComes.GetValueOrDefault(x + y + z, 0ul) + 1ul;
for (var y = 1; y <= 3; y++)
for (var z = 1; z <= 3; z++)
_possibleRollOutComes[x + y + z] =
_possibleRollOutComes.GetValueOrDefault(x + y + z, 0ul) + 1ul;
RollDiracDie(0, 0, _player1, _player2, 1, 1);

View File

@ -12,21 +12,21 @@ public sealed class Day12() : Day(2022, 12, "Hill Climbing Algorithm")
public override void ProcessInput()
{
foreach (var (y, line) in Input.Indexed())
foreach (var (x, c) in line.Indexed())
switch (c)
{
case 'S':
_startCoord = (x, y);
_grid[(x, y)] = 0;
break;
case 'E':
_destCoord = (x, y);
_grid[(x, y)] = 25;
break;
default:
_grid[(x, y)] = c - 'a';
break;
}
foreach (var (x, c) in line.Indexed())
switch (c)
{
case 'S':
_startCoord = (x, y);
_grid[(x, y)] = 0;
break;
case 'E':
_destCoord = (x, y);
_grid[(x, y)] = 25;
break;
default:
_grid[(x, y)] = c - 'a';
break;
}
}
private int ShortestDistance((int x, int y) startCoord, (int x, int y)? destCoord, int? destVal = null)