Added day 6 part 1
This commit is contained in:
parent
ea203f1b25
commit
dd7cc6f542
@ -10,7 +10,7 @@ IChallange challange = Host.CreateDefaultBuilder()
|
||||
.Build()
|
||||
.Services
|
||||
.GetService<SolutionManager>()
|
||||
.GetChallange(2024, 5);
|
||||
.GetChallange(2024, 6);
|
||||
|
||||
Console.WriteLine($"Part 1: {await challange.GetSolutionPart1()}");
|
||||
|
||||
|
||||
93
AdventOfCode.Solutions/2024/Day 06/Day06.cs
Normal file
93
AdventOfCode.Solutions/2024/Day 06/Day06.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using AdventOfCode.Core.Shared.IO;
|
||||
|
||||
namespace AdventOfCode.Solutions._2024
|
||||
{
|
||||
public class Day06 : IChallange
|
||||
{
|
||||
public int Year => 2024;
|
||||
|
||||
public int Day => 6;
|
||||
|
||||
private readonly IInputReader _inputReader;
|
||||
|
||||
public Day06(IInputReader inputReader)
|
||||
{
|
||||
_inputReader = inputReader;
|
||||
_inputReader.SetInput(this);
|
||||
//_inputReader.SetSampleInput(true);
|
||||
}
|
||||
|
||||
// 41
|
||||
// 4696
|
||||
public async Task<string> GetSolutionPart1()
|
||||
{
|
||||
Grid<Point> map = await _inputReader.ReadToGrid<Point>();
|
||||
Point current = map.DataGrid.Single(p => p.Value == '^');
|
||||
HashSet<Point> points = [current];
|
||||
Point move = new Point(0, -1);
|
||||
|
||||
do
|
||||
{
|
||||
// check if we are done
|
||||
long nextX = current.X + move.X,
|
||||
nextY = current.Y + move.Y;
|
||||
if (nextX == -1 || nextX == map.Columns
|
||||
|| nextY == -1 || nextY == map.Rows)
|
||||
break;
|
||||
|
||||
// get next
|
||||
Point next = map.GetNode(nextX, nextY);
|
||||
if (next.Value == '#')
|
||||
{
|
||||
move = Turn(move);
|
||||
//Console.WriteLine("turned " + move.ToString());
|
||||
continue;
|
||||
}
|
||||
|
||||
points.Add(next);
|
||||
current = next;
|
||||
//Console.WriteLine("moved " + current.ToString());
|
||||
}
|
||||
while (true);
|
||||
|
||||
return points.Count.ToString();
|
||||
}
|
||||
|
||||
// 6
|
||||
//
|
||||
public async Task<string> GetSolutionPart2()
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private Point Turn(Point currentDir)
|
||||
{
|
||||
if (currentDir.Y == -1 && currentDir.X == 0)
|
||||
{
|
||||
currentDir.Y = 0;
|
||||
currentDir.X = 1;
|
||||
return currentDir;
|
||||
}
|
||||
else if (currentDir.Y == 0 && currentDir.X == 1)
|
||||
{
|
||||
currentDir.Y = 1;
|
||||
currentDir.X = 0;
|
||||
return currentDir;
|
||||
}
|
||||
else if (currentDir.Y == 1 && currentDir.X == 0)
|
||||
{
|
||||
currentDir.Y = 0;
|
||||
currentDir.X = -1;
|
||||
return currentDir;
|
||||
}
|
||||
else if(currentDir.Y == 0 && currentDir.X == -1)
|
||||
{
|
||||
currentDir.Y = -1;
|
||||
currentDir.X = 0;
|
||||
return currentDir;
|
||||
}
|
||||
|
||||
throw new InvalidDataException();
|
||||
}
|
||||
}
|
||||
}
|
||||
130
AdventOfCode.Solutions/2024/Day 06/day-06-input.txt
Normal file
130
AdventOfCode.Solutions/2024/Day 06/day-06-input.txt
Normal file
@ -0,0 +1,130 @@
|
||||
.#......................................#................#....#.......##..........................#.....#......#..................
|
||||
......#...#...................................#......#...#........#...........................................#.#.................
|
||||
.....................................................#.......#.............#................#...............#...#...........#.....
|
||||
..........#...#.......#...........#.......................................#..............#.......#.#......#...............#.......
|
||||
...#.......................................................................#.................................................#....
|
||||
.......#.....#................#.......#..................#......#...........#...............................#.....................
|
||||
.........#.......#..#...........................#........#.........................#..#.....#.....................................
|
||||
..........#.......##....................#..............##..##..#...#........................................................#.....
|
||||
................#............................................................#.......................#...#........................
|
||||
...............................................................................................#...........................#......
|
||||
#.....#..............#...............#.........#................................................................#........#........
|
||||
.....#..#.................................#......................................................................#................
|
||||
............................................#.....................................................................................
|
||||
.............#....................................#.................#...##........#....#....#.....................................
|
||||
.............#.............#...........##..............#.........#....#................#....................#.....................
|
||||
..#..#...#.............#....................................#.........................................................#...........
|
||||
........................#......#...........#.....#....................#.........................#.................................
|
||||
.................#................................................................................................................
|
||||
.........#.......#..........#...............#................................#........................#.........#......#..........
|
||||
.........................................#.........#..........#.........#........................#......................#.........
|
||||
.#.....................#.............................#.....................#.............................................#........
|
||||
...#..#........#...............#......................#..................#........................................#...#...........
|
||||
..#...........#..........#......#...............#...............................................................#.................
|
||||
......#..#.............................#.#..............#......#..................................................................
|
||||
......#..........#....#...#.........#...................................................................#...........#.............
|
||||
............#....#.....#..............................................#.......#..............#........................#...........
|
||||
......#.................#...............................................................................#...................#.....
|
||||
................#................#............................................................................#.....##............
|
||||
.........#......................................#....#......#.......................................#........##..........#........
|
||||
#........#.........................................#..........#..............#.......#............................................
|
||||
.#..........##....................#......................................................................#................#..#....
|
||||
...........................................#............................#..........................#....................#.........
|
||||
......#.......................#.............#......................................................................#..............
|
||||
..#.#.....#...#....#....#......#..................................#...................#...........................................
|
||||
..#................................#...................................#...#..................................#.......#...........
|
||||
....#...............#....................................#..#..............#.........#.........#.#..............................#.
|
||||
..........#......#.........................#.#.................................#...........................................#.....#
|
||||
..................##.................#...........#................................#.............................................#.
|
||||
.....#......#................#....................................................#..............#.........................#......
|
||||
#..............#........#..............................#...........#...............#.....#.............................#..........
|
||||
..............#.........................#........................................................#..........................#..##.
|
||||
...............................................................#..............................................#...................
|
||||
......................#.............................................................##.........#...........................#.#....
|
||||
.......#................................#................#...........................#...................#.........#..............
|
||||
.................................................................#...#.............#.....#...............#........................
|
||||
..............................................................#..#...............................#.......#...............#.#......
|
||||
.....#.................#......................#..........................................#........................................
|
||||
..............................#...............#......#..........#........................#................#......#................
|
||||
.............................................#.........#..................................................................#.......
|
||||
......#..........................#.............#....................................................#................#............
|
||||
..................#..............................................#..........................................#.....................
|
||||
..#.........................................#..............................#...#........................................#..#......
|
||||
........#........................#................................................................................................
|
||||
...............#...............................#.............#...........................#........................................
|
||||
...............................................................................................#....#.............................
|
||||
............#.....................#...........#.............#.......#..............#.....#.............................#...#......
|
||||
..........#..........................................................#.#.......#..................................................
|
||||
...#................................#.....................................................................#...................#...
|
||||
...#..#...........................#............................#........#.......#.#..........#.......#............................
|
||||
...................##......................................#..................##..............................#........#..........
|
||||
................##.....................................................................#....................................#.....
|
||||
....#......................................................#..............#....#.................................#................
|
||||
......................#...#............................................................................................#..........
|
||||
..#......................#.................................................#.....#.....................................##.........
|
||||
....................##.......................#............#.#....#......#...........#.............#..#................#...#....##.
|
||||
.....................................................................................#....#..........#............................
|
||||
..................#...............................................#.....#..#............#.....................##.............#....
|
||||
......#.................................................................#.....#........#..#.......................................
|
||||
......#..............................................#........#................#..................................................
|
||||
........#........#...........#....................#...............................#..........................................#....
|
||||
.##............................................................#............#..............................................#......
|
||||
........................#............................#.....#....................#............#....................................
|
||||
...#......#.............#..#..#........#...............................................................................#..#....#..
|
||||
#.....#...............................................#...#....#................#....#....................................#.......
|
||||
.................................#..#...........................................................................................#.
|
||||
..........#.........................#.....................#............................................#..........................
|
||||
..............................#........#...................................#..#................................#...#.............#
|
||||
...#....................#.............................#..............................#..#..#......................................
|
||||
..........#...................#....................#.....##............................#.....................#....................
|
||||
.................#..........#.........................##.....................................................#.........#..........
|
||||
..........................................................#....................................#..........#.......................
|
||||
.........................................................#.....#..#.................#..............................#..............
|
||||
................#..................#...............#.............#......#............#.................#...................##.....
|
||||
...................#.....#...............................#.................................#.........##...........................
|
||||
......................#..........#..........#...................................#..............#......#...........................
|
||||
...........................................................#......#...#.....................#.....#.......................#....#..
|
||||
.....................#.........................#.......#.........#................................#.#....................#......#.
|
||||
...............................#..............................................#......#.................................#........#.
|
||||
........#...........................................#...#.........................................#.........................#..#..
|
||||
..............#............................#.....#.....#.......#...^...........................#................#.........#.......
|
||||
..........#.#..............#.........#.............#............................................................#.................
|
||||
.......#..#......#.......................................................................#........................................
|
||||
..........#..........................##.............#.....#..........#.............................................#..............
|
||||
................#............#.....#................#....#......................................................#........#........
|
||||
..#......................##.......................##.....#.....#.............................................#....................
|
||||
....#...........#.................................................##........................#...#..#..............................
|
||||
...........#..........................#..........................................#...#............................................
|
||||
##......#.........#...........#...#................................##................#...................##......#................
|
||||
.....................#...............#.............#..........#.#..................#....................#.......#.................
|
||||
...#..#.....#............#.....#......#.#.........................................................................................
|
||||
...#..............................................................................................................#.........#.....
|
||||
..................#..........................#.................................................#..................................
|
||||
..........#...................................#.......#..#.....#.................#............##.#......#........#...#............
|
||||
.......#....#............................................................................#.......................#................
|
||||
.......................#...................#..#.......#..#.............#................#.........................................
|
||||
........#......................#.......#...........#......##................##..#......#.#....#........#..........................
|
||||
...#..................................#........................#.....#..#.........................................................
|
||||
..#.......#...........#.........#.##..........#...........................................#...........................#...........
|
||||
...................#........................................#...........#.................#.#......................#.#............
|
||||
#......................#.............................#................................#.............#....#...........#............
|
||||
.........#...........................................#.....#......................................#.......................#.......
|
||||
.......................#.#...............................#........................................................................
|
||||
...........................#...............................................................#..............#.......................
|
||||
.......##..................#..........#......#.....................#.#.............................##..#.................#........
|
||||
#.#...........#..........................................................#.....#...##......#......................#..#............
|
||||
..#.............................#................#.#.........##..........................................................#........
|
||||
.......................................#.......................................#...#.........#.............#......................
|
||||
....#.##................................................#....................................................#.#...........#......
|
||||
...#............................#.....#............#..................................#..........................................#
|
||||
.........#...#..................................#.................#................................#...#..........................
|
||||
.....................................#.............................#...#..........#.................#........#.......#............
|
||||
.........##........#.#.....................................................................................................#......
|
||||
...............................#....#.......#............#......#...................................#...............#.............
|
||||
....##.#.............................##..........#....#...................#..........................#......#.#.#.................
|
||||
............#.........#.....#..............................#......................................................................
|
||||
..........#...#...#.......................#.............#...................#.##.......#.................#......#.................
|
||||
..#..#..#...............................#.............#.................................................................#...#.....
|
||||
.......................#..#.......................#..............#............#..........#........#..............................#
|
||||
.....#...............#...##...........#..................#........................................#.....#.....#...................
|
||||
....#.....................................#..........#..........#..#.....#...#....#...#...............#..........................#
|
||||
@ -34,6 +34,9 @@
|
||||
<Compile Update="2023\Day 13\Day13.cs">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
<Compile Update="2024\Day 06\Day06.cs">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
<Compile Update="2024\Day 05\Day05.cs">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using AdventOfCode.Core.Shared.IO;
|
||||
|
||||
namespace AdventOfCode.Solutions._2024
|
||||
namespace AdventOfCode.Solutions
|
||||
{
|
||||
public class Day00 : IChallange
|
||||
{
|
||||
@ -13,6 +13,7 @@ namespace AdventOfCode.Solutions._2024
|
||||
public Day00(IInputReader inputReader)
|
||||
{
|
||||
_inputReader = inputReader;
|
||||
_inputReader.SetInput(this);
|
||||
}
|
||||
public async Task<string> GetSolutionPart1()
|
||||
{
|
||||
|
||||
@ -1,28 +1,10 @@
|
||||
47|53
|
||||
97|13
|
||||
97|61
|
||||
97|47
|
||||
75|29
|
||||
61|13
|
||||
75|53
|
||||
29|13
|
||||
97|29
|
||||
53|29
|
||||
61|53
|
||||
97|53
|
||||
61|29
|
||||
47|13
|
||||
75|47
|
||||
97|75
|
||||
47|61
|
||||
75|61
|
||||
47|29
|
||||
75|13
|
||||
53|13
|
||||
|
||||
75,47,61,53,29
|
||||
97,61,53,29,13
|
||||
75,29,13
|
||||
75,97,47,61,53
|
||||
61,13,29
|
||||
97,13,75,29,47
|
||||
....#.....
|
||||
.........#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#..^.....
|
||||
........#.
|
||||
#.........
|
||||
......#...
|
||||
Loading…
Reference in New Issue
Block a user