diff --git a/Advend Of Code Runner/Advent Of Code Runner.csproj b/Advend Of Code Runner/AdventOfCode.Runner.csproj
similarity index 78%
rename from Advend Of Code Runner/Advent Of Code Runner.csproj
rename to Advend Of Code Runner/AdventOfCode.Runner.csproj
index 8a96168..85e936f 100644
--- a/Advend Of Code Runner/Advent Of Code Runner.csproj
+++ b/Advend Of Code Runner/AdventOfCode.Runner.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/Advend Of Code Runner/Program.cs b/Advend Of Code Runner/Program.cs
index c7b515f..7e2cc12 100644
--- a/Advend Of Code Runner/Program.cs
+++ b/Advend Of Code Runner/Program.cs
@@ -3,37 +3,15 @@
using AdventOfCodeLibrary._2022;
using AdventOfCodeLibrary.Shared;
-string _demoData = @"Monkey 0:
- Starting items: 79, 98
- Operation: new = old * 19
- Test: divisible by 23
- If true: throw to monkey 2
- If false: throw to monkey 3
+string _demoData = @"Sabqponm
+abcryxxl
+accszExk
+acctuvwj
+abdefghi";
-Monkey 1:
- Starting items: 54, 65, 75, 74
- Operation: new = old + 6
- Test: divisible by 19
- If true: throw to monkey 2
- If false: throw to monkey 0
-
-Monkey 2:
- Starting items: 79, 60, 97
- Operation: new = old * old
- Test: divisible by 13
- If true: throw to monkey 1
- If false: throw to monkey 3
-
-Monkey 3:
- Starting items: 74
- Operation: new = old + 3
- Test: divisible by 17
- If true: throw to monkey 0
- If false: throw to monkey 1";
-
-Answerable answerable = new Day11Part2();
+Answerable answerable = new Day12Part1();
byte[] dataArray = File.ReadAllBytes(answerable.DefaultInputFile);
-//dataArray = Encoding.UTF8.GetBytes(_demoData);
+dataArray = Encoding.UTF8.GetBytes(_demoData);
Console.WriteLine($"Answer: {answerable.GetAnswer(dataArray)}");
Console.ReadKey(true);
\ No newline at end of file
diff --git a/Advent Of Code Library/2022/Day 12/Day12Part1.cs b/Advent Of Code Library/2022/Day 12/Day12Part1.cs
index d65b250..af48497 100644
--- a/Advent Of Code Library/2022/Day 12/Day12Part1.cs
+++ b/Advent Of Code Library/2022/Day 12/Day12Part1.cs
@@ -10,6 +10,20 @@
public override string GetAnswer(byte[] data)
{
+ int totalWidth = data.First(b => b == 10 || b == 13);
+ int totalHeigth = data.Count(b => b == 10);
+
+ int[][] map = new int[totalHeigth][];
+
+ for (int heigthIndex = 0; heigthIndex <= totalHeigth; heigthIndex++)
+ {
+ map[heigthIndex] = new int[totalWidth];
+ for (int widthIndex = 0; widthIndex <= totalWidth; widthIndex++)
+ {
+
+ }
+ }
+
return string.Empty;
}
}
diff --git a/Advent Of Code Library/2022/Day 12/Map.cs b/Advent Of Code Library/2022/Day 12/Map.cs
new file mode 100644
index 0000000..5f2dfcc
--- /dev/null
+++ b/Advent Of Code Library/2022/Day 12/Map.cs
@@ -0,0 +1,10 @@
+namespace AdventOfCodeLibrary._2022.Day_12
+{
+ internal class Map
+ {
+ internal void BuildMap(string[] mapData)
+ {
+
+ }
+ }
+}
diff --git a/Advent Of Code Library/Advent Of Code Library.csproj b/Advent Of Code Library/AdventOfCode.Library.csproj
similarity index 100%
rename from Advent Of Code Library/Advent Of Code Library.csproj
rename to Advent Of Code Library/AdventOfCode.Library.csproj
diff --git a/Advent Of Code Library/Shared/A-Star/AStarGrid.cs b/Advent Of Code Library/Shared/A-Star/AStarGrid.cs
new file mode 100644
index 0000000..830afa8
--- /dev/null
+++ b/Advent Of Code Library/Shared/A-Star/AStarGrid.cs
@@ -0,0 +1,46 @@
+namespace AdventOfCodeLibrary.Shared.A_Star
+{
+ public class AStarGrid : Grid
+ {
+ const int TILE_MOVE_COST = 10;
+
+ public AStarGrid(AStarNode[] data) : base(data)
+ {
+ }
+
+ public int MinimalSteps(AStarNode start, AStarNode destination)
+ {
+ List closedNodes = new();
+ List openNodes = new List { start };
+
+ do
+ {
+ AStarNode current = openNodes.OrderBy(n => n.FCost).First();
+ openNodes.Remove(current);
+ current.CloseNode();
+ closedNodes.Add(current);
+
+ if (current == destination)
+ {
+ //done
+ return 1;
+ }
+
+ var neighbors = GetNeighbors(current, false);
+ neighbors = neighbors.Where(n => current.CanMoveTo(n));
+
+ // calc costs
+ foreach(AStarNode neighbor in neighbors)
+ {
+ neighbor.ParentNode = current;
+ // since we only move straight the move cost is always the same
+ neighbor.GCost = current.GCost + TILE_MOVE_COST;
+ neighbor.HCost = neighbor.DistanceTo(destination) * TILE_MOVE_COST;
+ neighbor.OpenNode();
+ openNodes.Add(neighbor);
+ }
+ }
+ while (true);
+ }
+ }
+}
diff --git a/Advent Of Code Library/Shared/A-Star/AStarNode.cs b/Advent Of Code Library/Shared/A-Star/AStarNode.cs
new file mode 100644
index 0000000..fde509d
--- /dev/null
+++ b/Advent Of Code Library/Shared/A-Star/AStarNode.cs
@@ -0,0 +1,40 @@
+namespace AdventOfCodeLibrary.Shared.A_Star
+{
+ public class AStarNode : Node
+ {
+ ///
+ /// Distance from start node
+ ///
+ public int GCost { get; set; } = 0;
+
+ ///
+ /// Distance from end node
+ ///
+ public int HCost { get; set; }
+
+ ///
+ /// Total cost (G + F)
+ ///
+ public int FCost => GCost + HCost;
+
+ public bool? IsClosed { get; private set; } = null;
+
+ public AStarNode? ParentNode { get; set; }
+
+ public AStarNode(Node position) : base(position)
+ { }
+
+ public AStarNode(int x, int y, char value) : base(x, y, value)
+ { }
+
+ public void OpenNode() => IsClosed = false;
+
+ public void CloseNode() => IsClosed = true;
+
+ public bool CanMoveTo(AStarNode target)
+ {
+ int diff = target.Integer - Integer; ;
+ return diff == 0 || diff == 1;
+ }
+ }
+}
diff --git a/Advent Of Code Library/Shared/Grid.cs b/Advent Of Code Library/Shared/Grid.cs
new file mode 100644
index 0000000..394507d
--- /dev/null
+++ b/Advent Of Code Library/Shared/Grid.cs
@@ -0,0 +1,30 @@
+using System.Collections.Generic;
+
+namespace AdventOfCodeLibrary.Shared
+{
+ public class Grid where T : Node
+ {
+ public List DataGrid { get; set; } = new List();
+
+ public Grid(T[] data) => DataGrid.AddRange(data);
+
+ public Grid(IEnumerable data) : this(data.ToArray()) { }
+
+ public IEnumerable GetRow(int rowNumber) => DataGrid.Where(n => n.X == rowNumber);
+ public IEnumerable GetColumn(int columnNumber) => DataGrid.Where(n => n.Y == columnNumber);
+
+ public IEnumerable GetNeighbors(T source, bool allowDiagonals = true)
+ {
+ IEnumerable neighbors = DataGrid.Where(target => Math.Abs(source.X - target.X) <= 1 || Math.Abs(source.Y - target.Y) <= 1);
+
+ if (allowDiagonals)
+ {
+ return neighbors;
+ }
+
+ return neighbors.Where(target => !(Math.Abs(source.X - target.X) <= 1 && Math.Abs(source.Y - target.Y) <= 1));
+
+ }
+ }
+
+}
diff --git a/Advent Of Code Library/Shared/Node.cs b/Advent Of Code Library/Shared/Node.cs
new file mode 100644
index 0000000..7b13c7c
--- /dev/null
+++ b/Advent Of Code Library/Shared/Node.cs
@@ -0,0 +1,25 @@
+namespace AdventOfCodeLibrary.Shared
+{
+ public class Node
+ {
+ internal int X { get; set; }
+ internal int Y { get; set; }
+ internal char Char { get; }
+ internal short Integer => (short)Char;
+
+ public Node(int x, int y, char character)
+ {
+ X = x;
+ Y = y;
+ Char = character;
+ }
+
+ public Node(Node position) : this(position.X, position.Y, position.Char)
+ { }
+
+ public int DistanceTo(Node other)
+ {
+ return Math.Abs(X - other.X) + Math.Abs(Y - other.Y);
+ }
+ }
+}
diff --git a/Advent Of Code.sln b/Advent Of Code.sln
index 51a731f..45c7b09 100644
--- a/Advent Of Code.sln
+++ b/Advent Of Code.sln
@@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33103.184
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Advent Of Code Runner", "Advend Of Code Runner\Advent Of Code Runner.csproj", "{6DCDC513-AF72-4029-932A-A0079BB5422B}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdventOfCode.Runner", "Advend Of Code Runner\AdventOfCode.Runner.csproj", "{6DCDC513-AF72-4029-932A-A0079BB5422B}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Advent Of Code Library", "Advent Of Code Library\Advent Of Code Library.csproj", "{33CC3924-F18E-4B88-9989-A7A9077B9AC4}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdventOfCode.Library", "Advent Of Code Library\AdventOfCode.Library.csproj", "{33CC3924-F18E-4B88-9989-A7A9077B9AC4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution