Skip to content

Commit

Permalink
prep 22
Browse files Browse the repository at this point in the history
  • Loading branch information
lucafluri committed Dec 22, 2023
1 parent 53cbe04 commit a91f8d0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion AdventOfCode/Day21.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public int FindPaths(int step, (int, int) start)
(x, y) = queue.Dequeue();
foreach (var (dx, dy) in dirs)
{
var (nx, ny) = (dx + x, dy + y);
var (nx, ny) = (dx + x, dy + y);
var (tx, ty) = ((nx % _width + _width) % _width, (ny % _height + _height) % _height);
if (_grid.ContainsKey((tx, ty)) &&
(_grid[(tx, ty)] == '#' || visited.ContainsKey((nx, ny)))) continue;
Expand Down
49 changes: 45 additions & 4 deletions AdventOfCode/Day22.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
using System.Text.RegularExpressions;
using System.Data;
using System.Text.RegularExpressions;

namespace AdventOfCode;

public class Day22 : BaseDay
{
private List<string> _input;

private List<Brick> _bricks;

class Brick
{
public List<(int, int, int)> blocks;

public Brick(string line)
{
var ends = line.Split("~");
var start = ends[0].Split(",");
var end = ends[1].Split(",");

blocks = new List<(int, int, int)>();
for (int i = int.Parse(start[0]); i <= int.Parse(end[0]); i++)
{
for (int j = int.Parse(start[1]); j <= int.Parse(end[1]); j++)
{
for (int k = int.Parse(start[2]); k <= int.Parse(end[2]); k++)
{
blocks.Add((i, j, k));
}
}
}
}

public override string ToString()
{
// Print all blocks in format: x,y,z
return string.Join("", blocks.Select(block => $"{block.Item1},{block.Item2},{block.Item3}\n"));
}
}

public Day22()
{
_input = File.ReadAllLines(InputFilePath).ToList();
_bricks = File.ReadAllLines(InputFilePath).Select(line => new Brick(line)).ToList();



// Sort bricks by z lowest value
_bricks = _bricks.OrderBy(b => b.blocks.Min(block => block.Item3)).ToList();

foreach (var b in _bricks)
{
Console.WriteLine(b);
// Console.WriteLine();
}
}

public override ValueTask<string> Solve_1()
Expand Down
7 changes: 7 additions & 0 deletions AdventOfCode/Inputs/22.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1,0,1~1,2,1
0,0,2~2,0,2
0,2,3~2,2,3
0,0,4~0,2,4
2,0,5~2,2,5
0,1,6~2,1,6
1,1,8~1,1,9
2 changes: 1 addition & 1 deletion AdventOfCode/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ await Solver.SolveAll(opt =>
// var indexes = args.Select(arg => uint.TryParse(arg, out var index) ? index : uint.MaxValue);

// await Solver.Solve(indexes.Where(i => i < uint.MaxValue));
await Solver.Solve<Day19>(opt =>
await Solver.Solve<Day21>(opt =>
{
opt.ShowConstructorElapsedTime = true;
opt.ShowTotalElapsedTimePerDay = true;
Expand Down

0 comments on commit a91f8d0

Please sign in to comment.