Initial Commit
This commit is contained in:
10
2022/Day17CSharp/Day17CSharp.csproj
Normal file
10
2022/Day17CSharp/Day17CSharp.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
107
2022/Day17CSharp/Program.cs
Normal file
107
2022/Day17CSharp/Program.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
|
||||
using System.Drawing;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
var exampleChamber = new Chamber(7, "example-input.txt");
|
||||
|
||||
var puzzleChamber = new Chamber(7, "puzzle-input.txt");
|
||||
|
||||
abstract class Shape
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Chamber bottom right is 0,0. Y points up. 0,0 is a "block"
|
||||
class Chamber
|
||||
{
|
||||
public enum WindDirection
|
||||
{
|
||||
Left,
|
||||
Right,
|
||||
None
|
||||
}
|
||||
|
||||
public HashSet<Point> FilledSpaces { get; set; }
|
||||
|
||||
public int ChamberWidth { get; private set; }
|
||||
|
||||
public WindDirection[] WindDirections { get; private set; }
|
||||
|
||||
public Chamber(int chamberWidth, string windfile)
|
||||
{
|
||||
FilledSpaces = new HashSet<Point>();
|
||||
ChamberWidth = chamberWidth;
|
||||
|
||||
using (StreamReader reader = System.IO.File.OpenText(windfile))
|
||||
{
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
var line = reader.ReadLine();
|
||||
if (line == null) throw new InvalidDataException();
|
||||
|
||||
WindDirections = new WindDirection[line.Length];
|
||||
|
||||
for (int i = 0; i < WindDirections.Length; i++)
|
||||
{
|
||||
if (line[i] == '<')
|
||||
WindDirections[i] = WindDirection.Left;
|
||||
else if (line[i] == '>')
|
||||
WindDirections[i] = WindDirection.Right;
|
||||
else
|
||||
throw new InvalidDataException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (WindDirections == null) throw new InvalidDataException();
|
||||
}
|
||||
|
||||
public Rectangle Bounds
|
||||
{
|
||||
get
|
||||
{
|
||||
Point min = new Point(1,1), max = new Point(1,1);
|
||||
|
||||
foreach (var item in FilledSpaces)
|
||||
{
|
||||
min.X = int.Min(min.X, item.X);
|
||||
min.Y = int.Min(min.Y, item.Y);
|
||||
max.X = int.Max(max.X, item.X);
|
||||
max.Y = int.Max(max.Y, item.Y);
|
||||
}
|
||||
|
||||
return new Rectangle(0, 0, max.X - min.X, max.Y - min.Y);
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
var bounds = Bounds;
|
||||
|
||||
int maxY = bounds.Height;
|
||||
for (int j = maxY; j > 0; j--)
|
||||
{
|
||||
Console.Write("|");
|
||||
for (int i = 1; i <= ChamberWidth; i++)
|
||||
{
|
||||
if (FilledSpaces.Contains(new Point(i,j)))
|
||||
{
|
||||
Console.Write('#');
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write('.');
|
||||
}
|
||||
}
|
||||
Console.WriteLine("|");
|
||||
}
|
||||
Console.Write("+");
|
||||
for (int i = 1; i <= ChamberWidth; i++)
|
||||
{
|
||||
Console.Write("-");
|
||||
}
|
||||
Console.WriteLine("+");
|
||||
}
|
||||
}
|
||||
8
2022/Day17CSharp/Properties/launchSettings.json
Normal file
8
2022/Day17CSharp/Properties/launchSettings.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"profiles": {
|
||||
"Day17CSharp": {
|
||||
"commandName": "Project",
|
||||
"workingDirectory": "C:\\dev\\DevSandbox\\AdventOfCode\\2022\\Day17CSharp"
|
||||
}
|
||||
}
|
||||
}
|
||||
1
2022/Day17CSharp/example-input.txt
Normal file
1
2022/Day17CSharp/example-input.txt
Normal file
@@ -0,0 +1 @@
|
||||
>>><<><>><<<>><>>><<<>>><<<><<<>><>><<>>
|
||||
337
2022/Day17CSharp/problem.txt
Normal file
337
2022/Day17CSharp/problem.txt
Normal file
@@ -0,0 +1,337 @@
|
||||
--- Day 17: Pyroclastic Flow ---
|
||||
|
||||
Your handheld device has located an alternative exit from the cave for you and the elephants. The ground is rumbling almost continuously now, but the strange valves bought you some time. It's definitely getting warmer in here, though.
|
||||
|
||||
The tunnels eventually open into a very tall, narrow chamber. Large, oddly-shaped rocks are falling into the chamber from above, presumably due to all the rumbling. If you can't work out where the rocks will fall next, you might be crushed!
|
||||
|
||||
The five types of rocks have the following peculiar shapes, where # is rock and . is empty space:
|
||||
|
||||
####
|
||||
|
||||
.#.
|
||||
###
|
||||
.#.
|
||||
|
||||
..#
|
||||
..#
|
||||
###
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
##
|
||||
##
|
||||
|
||||
The rocks fall in the order shown above: first the - shape, then the + shape, and so on. Once the end of the list is reached, the same order repeats: the - shape falls first, sixth, 11th, 16th, etc.
|
||||
|
||||
The rocks don't spin, but they do get pushed around by jets of hot gas coming out of the walls themselves. A quick scan reveals the effect the jets of hot gas will have on the rocks as they fall (your puzzle input).
|
||||
|
||||
For example, suppose this was the jet pattern in your cave:
|
||||
|
||||
>>><<><>><<<>><>>><<<>>><<<><<<>><>><<>>
|
||||
|
||||
In jet patterns, < means a push to the left, while > means a push to the right. The pattern above means that the jets will push a falling rock right, then right, then right, then left, then left, then right, and so on. If the end of the list is reached, it repeats.
|
||||
|
||||
The tall, vertical chamber is exactly seven units wide. Each rock appears so that its left edge is two units away from the left wall and its bottom edge is three units above the highest rock in the room (or the floor, if there isn't one).
|
||||
|
||||
After a rock appears, it alternates between being pushed by a jet of hot gas one unit (in the direction indicated by the next symbol in the jet pattern) and then falling one unit down. If any movement would cause any part of the rock to move into the walls, floor, or a stopped rock, the movement instead does not occur. If a downward movement would have caused a falling rock to move into the floor or an already-fallen rock, the falling rock stops where it is (having landed on something) and a new rock immediately begins falling.
|
||||
|
||||
Drawing falling rocks with @ and stopped rocks with #, the jet pattern in the example above manifests as follows:
|
||||
|
||||
The first rock begins falling:
|
||||
|..@@@@.|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
+-------+
|
||||
|
||||
Jet of gas pushes rock right:
|
||||
|...@@@@|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
+-------+
|
||||
|
||||
Rock falls 1 unit:
|
||||
|...@@@@|
|
||||
|.......|
|
||||
|.......|
|
||||
+-------+
|
||||
|
||||
Jet of gas pushes rock right, but nothing happens:
|
||||
|...@@@@|
|
||||
|.......|
|
||||
|.......|
|
||||
+-------+
|
||||
|
||||
Rock falls 1 unit:
|
||||
|...@@@@|
|
||||
|.......|
|
||||
+-------+
|
||||
|
||||
Jet of gas pushes rock right, but nothing happens:
|
||||
|...@@@@|
|
||||
|.......|
|
||||
+-------+
|
||||
|
||||
Rock falls 1 unit:
|
||||
|...@@@@|
|
||||
+-------+
|
||||
|
||||
Jet of gas pushes rock left:
|
||||
|..@@@@.|
|
||||
+-------+
|
||||
|
||||
Rock falls 1 unit, causing it to come to rest:
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
A new rock begins falling:
|
||||
|...@...|
|
||||
|..@@@..|
|
||||
|...@...|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
Jet of gas pushes rock left:
|
||||
|..@....|
|
||||
|.@@@...|
|
||||
|..@....|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
Rock falls 1 unit:
|
||||
|..@....|
|
||||
|.@@@...|
|
||||
|..@....|
|
||||
|.......|
|
||||
|.......|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
Jet of gas pushes rock right:
|
||||
|...@...|
|
||||
|..@@@..|
|
||||
|...@...|
|
||||
|.......|
|
||||
|.......|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
Rock falls 1 unit:
|
||||
|...@...|
|
||||
|..@@@..|
|
||||
|...@...|
|
||||
|.......|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
Jet of gas pushes rock left:
|
||||
|..@....|
|
||||
|.@@@...|
|
||||
|..@....|
|
||||
|.......|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
Rock falls 1 unit:
|
||||
|..@....|
|
||||
|.@@@...|
|
||||
|..@....|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
Jet of gas pushes rock right:
|
||||
|...@...|
|
||||
|..@@@..|
|
||||
|...@...|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
Rock falls 1 unit, causing it to come to rest:
|
||||
|...#...|
|
||||
|..###..|
|
||||
|...#...|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
A new rock begins falling:
|
||||
|....@..|
|
||||
|....@..|
|
||||
|..@@@..|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
|...#...|
|
||||
|..###..|
|
||||
|...#...|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
The moment each of the next few rocks begins falling, you would see this:
|
||||
|
||||
|..@....|
|
||||
|..@....|
|
||||
|..@....|
|
||||
|..@....|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
|..#....|
|
||||
|..#....|
|
||||
|####...|
|
||||
|..###..|
|
||||
|...#...|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
|..@@...|
|
||||
|..@@...|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
|....#..|
|
||||
|..#.#..|
|
||||
|..#.#..|
|
||||
|#####..|
|
||||
|..###..|
|
||||
|...#...|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
|..@@@@.|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
|....##.|
|
||||
|....##.|
|
||||
|....#..|
|
||||
|..#.#..|
|
||||
|..#.#..|
|
||||
|#####..|
|
||||
|..###..|
|
||||
|...#...|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
|...@...|
|
||||
|..@@@..|
|
||||
|...@...|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
|.####..|
|
||||
|....##.|
|
||||
|....##.|
|
||||
|....#..|
|
||||
|..#.#..|
|
||||
|..#.#..|
|
||||
|#####..|
|
||||
|..###..|
|
||||
|...#...|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
|....@..|
|
||||
|....@..|
|
||||
|..@@@..|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
|..#....|
|
||||
|.###...|
|
||||
|..#....|
|
||||
|.####..|
|
||||
|....##.|
|
||||
|....##.|
|
||||
|....#..|
|
||||
|..#.#..|
|
||||
|..#.#..|
|
||||
|#####..|
|
||||
|..###..|
|
||||
|...#...|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
|..@....|
|
||||
|..@....|
|
||||
|..@....|
|
||||
|..@....|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
|.....#.|
|
||||
|.....#.|
|
||||
|..####.|
|
||||
|.###...|
|
||||
|..#....|
|
||||
|.####..|
|
||||
|....##.|
|
||||
|....##.|
|
||||
|....#..|
|
||||
|..#.#..|
|
||||
|..#.#..|
|
||||
|#####..|
|
||||
|..###..|
|
||||
|...#...|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
|..@@...|
|
||||
|..@@...|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
|....#..|
|
||||
|....#..|
|
||||
|....##.|
|
||||
|....##.|
|
||||
|..####.|
|
||||
|.###...|
|
||||
|..#....|
|
||||
|.####..|
|
||||
|....##.|
|
||||
|....##.|
|
||||
|....#..|
|
||||
|..#.#..|
|
||||
|..#.#..|
|
||||
|#####..|
|
||||
|..###..|
|
||||
|...#...|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
|..@@@@.|
|
||||
|.......|
|
||||
|.......|
|
||||
|.......|
|
||||
|....#..|
|
||||
|....#..|
|
||||
|....##.|
|
||||
|##..##.|
|
||||
|######.|
|
||||
|.###...|
|
||||
|..#....|
|
||||
|.####..|
|
||||
|....##.|
|
||||
|....##.|
|
||||
|....#..|
|
||||
|..#.#..|
|
||||
|..#.#..|
|
||||
|#####..|
|
||||
|..###..|
|
||||
|...#...|
|
||||
|..####.|
|
||||
+-------+
|
||||
|
||||
To prove to the elephants your simulation is accurate, they want to know how tall the tower will get after 2022 rocks have stopped (but before the 2023rd rock begins falling). In this example, the tower of rocks will be 3068 units tall.
|
||||
|
||||
How many units tall will the tower of rocks be after 2022 rocks have stopped falling?
|
||||
1
2022/Day17CSharp/puzzle-input.txt
Normal file
1
2022/Day17CSharp/puzzle-input.txt
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user