Jelajahi Sumber

Day 23 part 1 - with validation and meta graph

Lukas Angerer 2 tahun lalu
induk
melakukan
9d0e2c939b
8 mengubah file dengan 480 tambahan dan 5 penghapusan
  1. 193 0
      Day23/Map.cs
  2. 16 5
      Day23/Parser.cs
  3. 7 0
      Day23/PathNode.cs
  4. 8 0
      Day23/Program.cs
  5. 38 0
      Day23/Tile.cs
  6. 54 0
      Day23/Vec.cs
  7. 141 0
      Day23/inputs/input-lar.txt
  8. 23 0
      Day23/inputs/sample1.txt

+ 193 - 0
Day23/Map.cs

@@ -0,0 +1,193 @@
+namespace Day23;
+
+public class Map
+{
+    private readonly int _width;
+    private readonly int _height;
+    private readonly Tile[,] _tiles;
+    private readonly Vec _start;
+    private readonly Vec _goal;
+    private PathNode? _root;
+
+    public Map(Tile[,] tiles)
+    {
+        _tiles = tiles;
+        _width = _tiles.GetLength(0);
+        _height = _tiles.GetLength(1);
+
+        _start = new Vec(1, 0);
+        _goal = new Vec(_width - 2, _height - 1);
+    }
+
+    public void Print()
+    {
+        foreach (var t in AllTiles())
+        {
+            if (t.Position.X == 0 && t.Position.Y != 0)
+            {
+                Console.WriteLine();
+            }
+            
+            Console.Write(t.Value);
+        }
+
+        Console.WriteLine();
+    }
+
+    public void Verify()
+    {
+        Assert(At(_start)?.IsPath ?? false);
+        Assert(At(_goal)?.IsPath ?? false);
+        
+        foreach (var t in AllTiles())
+        {
+            if (t.IsPath)
+            {
+                var neighbors = Neighbors(t);
+                Assert(neighbors.Count != 0);
+                if (neighbors.Count == 1)
+                {
+                    Assert(t == At(_start) || t == At(_goal));
+                }
+                else if (neighbors.Count >= 3)
+                {
+                    Assert(neighbors.All(n => n.IsArrow));
+                }
+            }
+        }
+    }
+
+    public void BuildGraph()
+    {
+        var startTile = At(_start)!;
+        _root = BuildPath(startTile, Neighbors(startTile).Single().Position.Subtract(startTile.Position));
+
+        // Assert that we have no cycles in the graph
+        var seen = new HashSet<PathNode>();
+        foreach (var n in BreadthFirst())
+        {
+            if (seen.Contains(n))
+            {
+                throw new Exception("There is a cycle in the graph");
+            }
+
+            seen.Add(n);
+        }
+    }
+    
+    public int LongestPath()
+    {
+        Assert(_root != null);
+
+        var longest = 0;
+        var queue = new Queue<(PathNode Path, int Length)>();
+        queue.Enqueue((_root!, 0));
+        while (queue.Count > 0)
+        {
+            var (current, length) = queue.Dequeue();
+            var nextLength = length + current.Tiles.Count + 1;
+
+            if (current.Connected.Count == 0)
+            {
+                longest = int.Max(longest, nextLength);
+            }
+
+            foreach (var next in current.Connected)
+            {
+                queue.Enqueue((next, nextLength));
+            }
+        }
+
+        // start should not be counted (-1) and end is counted double (-1) 
+        return longest - 2;
+    }
+
+    private PathNode BuildPath(Tile start, Vec dir)
+    {
+        var pathNode = new PathNode();
+        pathNode.Tiles.AddRange(Follow(start, dir));
+
+        var crossing = At(pathNode.Tiles.Last().Position.Add(pathNode.Tiles.Last().ArrowDirection()))!;
+        crossing.Incoming.Add(pathNode);
+
+        if (crossing != At(_goal))
+        {
+            foreach (var outgoing in Neighbors(crossing)
+                         .Where(x => x.Position.Add(x.ArrowDirection()) != crossing.Position))
+            {
+                pathNode.Connected.Add(BuildPath(outgoing, outgoing.ArrowDirection()));
+            }
+        }
+
+        return pathNode;
+    }
+
+    private Tile? At(Vec p)
+    {
+        if (p.X < 0 || p.X >= _width || p.Y < 0 || p.Y >= _height)
+        {
+            return null;
+        }
+
+        return _tiles[p.X, p.Y];
+    }
+
+    private IEnumerable<Tile> AllTiles()
+    {
+        for (int y = 0; y < _height; y++)
+        {
+            for (int x = 0; x < _width; x++)
+            {
+                yield return At(new Vec(x, y))!;
+            }
+        }
+    }
+
+    private void Assert(bool condition)
+    {
+        if (!condition)
+        {
+            throw new Exception("Assertion FAILED");
+        }
+    }
+
+    private List<Tile> Neighbors(Tile tile)
+    {
+        return tile.Neighbors().Select(At).Where(x => x is { IsPath: true }).Cast<Tile>().ToList();
+    }
+
+    private IEnumerable<Tile> Follow(Tile start, Vec dir)
+    {
+        var visited = new HashSet<Vec>();
+        visited.Add(start.Position);
+        yield return start;
+
+        var current = At(start.Position.Add(dir))!;
+        while (!current.IsArrow && current != At(_goal))
+        {
+            visited.Add(current.Position);
+            yield return current;
+            current = Neighbors(current)
+                .Single(x => !visited.Contains(x.Position));
+        }
+
+        yield return current;
+    }
+
+    private IEnumerable<PathNode> BreadthFirst()
+    {
+        Assert(_root != null);
+        var queue = new Queue<PathNode>();
+        queue.Enqueue(_root!);
+        while (queue.Count > 0)
+        {
+            var current = queue.Dequeue();
+            yield return current;
+
+            foreach (var next in current.Connected)
+            {
+                queue.Enqueue(next);
+            }
+        }
+    }
+}

+ 16 - 5
Day23/Parser.cs

@@ -7,13 +7,24 @@ public partial class Parser
     [GeneratedRegex(@".*")]
     private partial Regex LineMatch();
     
-    public void Parse(string inputFile)
+    public Map Parse(string inputFile)
     {
-        using var reader = File.OpenText(inputFile);
-        
-        while (!reader.EndOfStream)
+        var lines = File.ReadAllLines(inputFile);
+
+        var width = lines[0].Length;
+        var height = lines.Length;
+        var tiles = new Tile[width, height];
+        var row = 0;
+
+        foreach (var line in lines)
         {
-            var line = reader.ReadLine()!;
+            for (var col = 0; col < width; col++)
+            {
+                tiles[col, row] = new Tile(line[col], new Vec(col, row));
+            }
+            row++;
         }
+
+        return new Map(tiles);
     }
 }

+ 7 - 0
Day23/PathNode.cs

@@ -0,0 +1,7 @@
+namespace Day23;
+
+public class PathNode
+{
+    public List<Tile> Tiles { get; } = new List<Tile>();
+    public List<PathNode> Connected { get; } = new List<PathNode>();
+}

+ 8 - 0
Day23/Program.cs

@@ -16,5 +16,13 @@ if (args.Length < 1)
 
 var inputFile = args[0];
 var parser = new Parser();
+var map = parser.Parse(inputFile);
+
+map.Verify();
+map.Print();
+map.BuildGraph();
+var steps = map.LongestPath();
+Console.WriteLine();
+Console.WriteLine($"Longest Path: {steps}");
 
 return 0;

+ 38 - 0
Day23/Tile.cs

@@ -0,0 +1,38 @@
+namespace Day23;
+
+public class Tile
+{
+    public char Value { get; }
+    public Vec Position { get; }
+    public IList<PathNode> Incoming { get; } = new List<PathNode>();
+    public IList<PathNode> Outgoing { get; } = new List<PathNode>();
+
+    public bool IsPath => Value == '.' || IsArrow;
+    public bool IsArrow => Value == '<' || Value == '>' || Value == '^' || Value == 'v';
+
+    public Tile(char value, Vec position)
+    {
+        Value = value;
+        Position = position;
+    }
+
+    public IEnumerable<Vec> Neighbors()
+    {
+        yield return Position.Add(Vec.Up);
+        yield return Position.Add(Vec.Right);
+        yield return Position.Add(Vec.Down);
+        yield return Position.Add(Vec.Left);
+    }
+
+    public Vec ArrowDirection()
+    {
+        return Value switch
+        {
+            '^' => Vec.Up,
+            'v' => Vec.Down,
+            '<' => Vec.Left,
+            '>' => Vec.Right,
+            _ => Vec.Zero
+        };
+    }
+}

+ 54 - 0
Day23/Vec.cs

@@ -0,0 +1,54 @@
+namespace Day23;
+
+public record struct Vec
+{
+    public static Vec Zero { get; } = new Vec(0, 0);
+    public static Vec Up { get; } = new Vec(0, -1);
+    public static Vec Down { get; } = new Vec(0, 1);
+    public static Vec Left { get; } = new Vec(-1, 0);
+    public static Vec Right { get; } = new Vec(1, 0);
+    
+    public long X { get; }
+    public long Y { get; }
+
+    public bool IsHorizontal => Y == 0;
+    public bool IsVertical => X == 0;
+
+    public Vec(long x, long y)
+    {
+        X = x;
+        Y = y;
+    }
+
+    public Vec RotatePositive()
+    {
+        // clockwise
+        return new Vec(-1 * Y, X);
+    }
+    
+    public Vec RotateNegative()
+    {
+        // counter-clockwise
+        return new Vec(Y, -1 * X);
+    }
+
+    public Vec Add(Vec other)
+    {
+        return new Vec(X + other.X, Y + other.Y);
+    }
+
+    public Vec Subtract(Vec other)
+    {
+        return new Vec(X - other.X, Y - other.Y);
+    }
+
+    public Vec Multiply(int f)
+    {
+        return new Vec(f * X, f * Y);
+    }
+
+    public long Cross(Vec other)
+    {
+        return X * other.Y - other.X * Y;
+    }
+}

+ 141 - 0
Day23/inputs/input-lar.txt

@@ -0,0 +1,141 @@
+#.###########################################################################################################################################
+#.....#...#####.......#.........#.......#...........#.....#.......#.....#...#...#...................#...#...#...#...#...#...#.......#.......#
+#####.#.#.#####.#####.#.#######.#.#####.#.#########.#.###.#.#####.#.###.#.#.#.#.#.#################.#.#.#.#.#.#.#.#.#.#.#.#.#.#####.#.#####.#
+#.....#.#.###...#.....#.#.......#.#.....#.........#...#...#.#.....#...#.#.#.#.#.#.................#.#.#...#.#.#...#.#.#.#.#.#.#.....#.#.....#
+#.#####.#.###.###.#####.#.#######.#.#############.#####.###.#.#######.#.#.#.#.#.#################.#.#.#####.#.#####.#.#.#.#.#.#.#####.#.#####
+#.#...#.#.#...#...#.....#.......#.#.#.....###...#.....#.....#...#...#.#.#.#.#.#.###...###...#.....#.#...#...#.#.....#.#.#.#.#.#.#.....#.....#
+#.#.#.#.#.#.###v###.###########.#.#.#.###.###.#.#####.#########.#.#.#.#.#.#.#.#.###.#.###.#.#.#####.###.#.###.#.#####.#.#.#.#.#.#.#########.#
+#.#.#.#.#...###.>...#...#.......#.#.#...#.#...#.#...#.#.........#.#.#.#.#.#.#.#...#.#...#.#...#...#.>.>.#...#.#...#...#.#.#.#.#...#...#...#.#
+#.#.#.#.#######v#####.#.#.#######.#.###.#.#.###.#.#.#.#.#########.#.#.#.#.#.#.###.#.###.#.#####.#.###v#####.#.###.#.###.#.#.#.#####.#.#.#.#.#
+#.#.#.#...#.....#.....#...#.....#.#.#...#.#...#...#...#...#.....#.#.#.#.#.#.#.#...#...#.#.......#...#.....#.#...#.#.#...#.#...###...#...#.#.#
+#.#.#.###.#.#####.#########.###.#.#.#.###.###.###########.#.###.#.#.#.#.#.#.#.#.#####.#.###########.#####.#.###.#.#.#.###.#######.#######.#.#
+#.#.#...#.#.....#...#...###.#...#.#.#...#...#.......#.....#.#...#.#...#.#.#...#.#.....#.###...#.....#...#.#.#...#.#.#.....#...#...###...#...#
+#.#.###.#.#####.###.#.#.###.#.###.#.###.###.#######.#.#####.#.###.#####.#.#####.#.#####.###.#.#.#####.#.#.#.#.###.#.#######.#.#.#####.#.#####
+#.#...#...#.....#...#.#...#.#.....#.###...#.###.....#.#.....#.###.....#.#.#.....#.#.....#...#...#.....#...#...###...#.......#...#.....#.....#
+#.###.#####.#####.###.###.#.#######.#####.#.###.#####.#.#####.#######.#.#.#.#####.#.#####.#######.###################.###########.#########.#
+#.#...#...#.....#.#...#...#...#.....#.....#...#.....#.#.#.....#.......#.#.#.#...#.#.#...#.......#.......#.......#.....#...#...#...#...#...#.#
+#.#.###.#.#####.#.#.###.#####.#.#####.#######.#####.#.#.#.#####.#######.#.#.#.#.#.#.#.#.#######.#######.#.#####.#.#####.#.#.#.#.###.#.#.#.#.#
+#.#.#...#.......#...#...#...#.#.>.>.#.....#...#...#.#.#.#.#...#.......#.#.#.#.#.#.#.#.#.###...#.#.......#.#...#.#.......#...#...#...#...#...#
+#.#.#.###############.###.#.#.###v#.#####.#.###.#.#.#.#.#.#.#.#######.#.#.#.#.#.#.#.#.#.###.#.#.#.#######.#.#.#.#################.###########
+#.#.#.#...#...#...###.....#.#.#...#...#...#.#...#.#.#.#.#.#.#...>.>.#.#.#.#.#.#.#.#.#.#.>.>.#.#.#.#...###.#.#...#...#...#...#...#...###...###
+#.#.#.#.#.#.#.#.#.#########.#.#.#####.#.###.#.###.#.#.#.#.#.#####v#.#.#.#.#.#.#.#.#.#.###v###.#.#.#.#.###.#.#####.#.#.#.#.#.#.#.###.###.#.###
+#.#.#.#.#.#.#...#.....#.....#.#.#...#...###...#...#.#.#.#.#.#.....#.#.#.#.#.#.#...#...#...#...#.#.#.#.....#...###.#...#...#...#...#.....#...#
+#.#.#.#.#.#.#########.#.#####.#.#.#.###########.###.#.#.#.#.#.#####.#.#.#.#.#.#########.###.###.#.#.#########.###.###############.#########.#
+#.#.#...#...#.........#...#...#...#.......#.....#...#...#...#.....#...#.#.#.#.#.....#...###.....#.#.#...#...#...#...#...........#...........#
+#.#.#########.###########.#.#############.#.#####.###############.#####.#.#.#.#.###.#.###########.#.#.#.#.#.###.###.#.#########.#############
+#.#.#...#.....#...#...###.#.#.........#...#.#...#.#.......###...#.....#...#...#...#.#.......#.....#.#.#...#.....#...#.###.......#...........#
+#.#.#.#.#.#####.#.#.#.###.#.#.#######.#.###.#.#.#.#.#####.###.#.#####.###########.#.#######.#.#####.#.###########.###.###.#######.#########.#
+#...#.#.#.....#.#...#...#...#...#...#...###...#...#.#.....#...#.#.....#...#...###.#.#.....#.#.#.....#...........#...#...#.#...#...#.........#
+#####.#.#####v#.#######.#######.#.#.###############.#.#####.###.#.#####.#.#.#.###.#.#.###.#.#.#.###############.###.###.#.#.#.#.###.#########
+#.....#.#...#.>.#.......#...###...#.#.....#.....###.#.#...#...#.#.###...#...#.....#...###...#...#...............###.....#...#.#.#...#...#...#
+#.#####.#.#.#v###.#######.#.#######.#.###.#.###.###.#.#.#.###.#.#v###.###########################.###########################.#.#.###.#.#.#.#
+#.....#...#...#...#.....#.#.#...#...#.#...#...#...#.#.#.#.#...#.>.>.#...................#.........#...............#.........#...#.....#...#.#
+#####.#########.###.###.#.#.#.#.#.###.#.#####.###.#.#.#.#.#.#####v#.###################.#.#########.#############.#.#######.###############.#
+#.....#.......#...#...#.#.#.#.#.#.....#...###...#.#.#.#.#.#...###.#.#...#...#...........#...........#.............#.....#...#...#.....#...#.#
+#.#####.#####.###.###.#.#.#.#.#.#########.#####.#.#.#.#.#.###.###.#.#.#.#.#.#.#######################.#################.#.###.#.#.###.#.#.#.#
+#.......#.....###...#.#.#.#.#.#...........#...#.#...#...#.#...#...#.#.#.#.#.#.......#...#...#.........#...........#...#.#.....#...###...#...#
+#########.#########.#.#.#.#.#.#############.#.#.#########.#.###.###.#.#.#.#.#######.#.#.#.#.#.#########.#########.#.#.#.#####################
+#.......#.....#...#.#.#...#.#.......#.....#.#.#.....#.....#.#...#...#.#.#.#.###.....#.#.#.#.#.........#...#.......#.#.#.................#...#
+#.#####.#####.#.#.#.#.#####.#######.#.###.#.#.#####.#.#####.#.###.###.#.#.#.###v#####.#.#.#.#########v###.#.#######.#.#################.#.#.#
+#.....#.......#.#...#.....#.#...###.#...#.#.#.#...#.#...#...#...#...#.#.#.#.#.>.>.....#.#.#.#...#...>.>.#.#.###...#.#.#...###...........#.#.#
+#####.#########.#########.#.#.#.###v###.#.#.#.#.#.#.###.#.#####.###.#.#.#.#.#.#v#######.#.#.#.#.#.###v#.#.#.###.#.#.#.#.#.###v###########.#.#
+#####.........#.......#...#...#...>.>.#.#.#.#.#.#...###.#.#.....###.#.#...#...#...#.....#.#.#.#.#.#...#...#.....#.#.#...#...>.###...#...#.#.#
+#############.#######.#.###########v#.#.#.#.#.#.#######.#.#.#######.#.###########.#.#####.#.#.#.#.#.#############.#.#########v###.#.#.#.#.#.#
+#.....#.......###.....#.......###...#...#...#.#...###...#.#.......#.#...#.........#...#...#.#.#.#.#.......#.......#.#.........#...#.#.#.#.#.#
+#.###.#.#########.###########.###.###########.###.###.###.#######.#.###.#.###########.#.###.#.#.#.#######.#.#######.#.#########.###.#.#.#.#.#
+#...#.#.........#.....#...#...#...#...#...###.....#...#...###.....#.....#...........#.#.###...#.#.#.......#...#...#.#...#.....#...#.#.#.#.#.#
+###.#.#########.#####.#.#.#.###.###.#.#.#.#########.###.#####.#####################.#.#.#######.#.#.#########.#.#.#.###.#.###.###.#.#.#.#.#.#
+#...#...........#.....#.#...###.....#...#.....#...#.....#...#.......#.....###...#...#...#...###...#.........#.#.#.#.###.#.#...#...#...#...#.#
+#.###############.#####.#####################.#.#.#######.#.#######.#.###.###.#.#.#######.#.###############.#.#.#.#.###.#.#.###.###########.#
+#...#.........#...#.....#.....###...........#...#...#.....#.........#...#.#...#.#...#.....#...###...#.......#...#...###.#.#.....#...#...#...#
+###.#.#######.#.###.#####.###.###.#########.#######.#.#################.#.#.###.###.#.#######.###.#.#.#################.#.#######.#.#.#.#.###
+#...#.#.......#.....#.....#...#...#...#...#.........#...........#.....#.#.#...#.....#.#.......#...#.#...###...###.....#...###...#.#...#...###
+#.###.#.#############.#####.###.###.#.#.#.#####################.#.###.#.#.###v#######.#.#######.###.###.###.#.###.###.#######.#.#.###########
+#.....#...........#...#...#.###.....#.#.#...#.....#...###...#...#...#.#.#.#.>.>.....#.#.#...#...#...###.....#...#.#...#.......#...###.......#
+#################.#.###.#.#.#########.#.###.#.###.#.#.###.#.#.#####.#.#.#.#.#v#####.#.#.#.#.#.###.#############.#.#.###.#############.#####.#
+#...#...#.........#.....#.#.#...#.....#.#...#...#...#.#...#.#.....#.#...#.#.#.#.....#.#.#.#.#.#...#...#.........#.#.###.....#.....#...#...#.#
+#.#.#.#.#.###############.#.#.#.#v#####.#.#####.#####.#.###.#####.#.#####.#.#.#.#####.#.#.#.#.#.###.#.#v#########.#.#######.#.###.#.###.#.#.#
+#.#.#.#.#.....#...#...#...#.#.#.>.>.....#.#...#.#.....#...#.......#.....#...#.#.#...#.#.#.#.#.#.#...#.>.>...#...#.#...#...#...###.#.#...#...#
+#.#.#.#.#####.#.#.#.#.#.###.#.###v#######.#.#.#.#.#######.#############.#####.#.#.#.#.#.#.#.#.#.#.#####v###.#.#.#.###.#.#.#######.#.#.#######
+#.#...#...#...#.#...#.#...#...###.....#...#.#.#.#.......#.........###...#.....#...#.#.#.#.#.#.#.#.#...#...#.#.#...#...#.#.###...#...#...#...#
+#.#######.#.###.#####.###.###########.#.###.#.#.#######.#########.###.###.#########.#.#.#.#.#.#.#.#.#.###.#.#.#####.###.#.###.#.#######.#.#.#
+#.......#.#...#.....#.#...#...........#.#...#...#.......#.........#...###.........#.#.#.#.#...#.#.#.#.....#...#.....#...#.#...#.#...###...#.#
+#######.#.###.#####.#.#.###.###########.#.#######.#######.#########.#############.#.#.#.#.#####.#.#.###########.#####.###.#.###.#.#.#######.#
+#.......#.....#...#.#...###...........#.#.#.......###...#.....#...#.......#.......#...#...#.....#.#.....###.....#...#...#.#.#...#.#.###.....#
+#.#############.#.#.#################.#.#.#.#########.#.#####v#.#.#######.#.###############.#####.#####.###.#####.#.###.#.#.#.###.#.###v#####
+#...#.......#...#.#.....#...#.........#.#.#...#.....#.#...#.>.>.#.#.......#...............#.....#.#...#...#...#...#.#...#.#.#.#...#.#.>.#...#
+###.#.#####v#.###.#####.#.#.#.#########.#.###.#.###.#.###.#.#v###.#.#####################.#####.#.#.#.###.###.#.###.#.###.#.#.#.###.#.#v#.#.#
+###...#...#.>.###.......#.#.#.....#...#...#...#.#...#.#...#.#...#.#.....#.................#.....#.#.#.....###.#.#...#.#...#.#.#.###...#.#.#.#
+#######.#.#v#############.#.#####.#.#.#####.###.#.###.#.###.###.#.#####.#.#################.#####.#.#########.#.#.###.#.###.#.#.#######.#.#.#
+###...#.#...###...#...###.#.#####...#.....#...#.#.....#...#.#...#.......#.................#.....#.#.........#...#...#.#.....#...###...#...#.#
+###.#.#.#######.#.#.#.###.#.#############.###.#.#########.#.#.###########################.#####.#.#########.#######.#.#############.#.#####.#
+#...#...#.....#.#.#.#...#.#.............#.#...#...#.......#.#.....###...#...#.............#...#...#...#.....#.....#...#.........#...#.......#
+#.#######.###.#.#.#.###.#.#############.#.#.#####.#.#######.#####.###.#.#.#.#.#############.#.#####.#.#.#####.###.#####.#######.#.###########
+#.#.....#.###.#.#...#...#.............#...#.......#.........#.....#...#.#.#.#.....#...#...#.#.#...#.#...#...#...#...###.......#.#...........#
+#.#.###.#.###.#.#####.###############.#######################.#####.###.#.#.#####.#.#.#.#.#.#.#.#.#.#####.#.###.###.#########.#.###########.#
+#.#.#...#.#...#.#.....#...###.......#.#...#...#...###...#.....#...#...#...#.###...#.#...#.#.#.#.#.#.......#.#...#...#.....#...#.#...#...#...#
+#.#.#.###.#.###.#.#####.#.###.#####.#.#.#.#.#.#.#.###.#.#.#####.#.###.#####.###v###.#####.#.#.#.#.#########.#.###.###.###.#.###.#.#.#.#.#.###
+#...#.....#.....#.......#...#.#...#.#.#.#.#.#.#.#.#...#.#...#...#.###.....#.#.>.>.#.#.....#.#.#.#.#.........#...#.###...#.#...#.#.#.#.#.#...#
+###########################.#.#.#.#.#.#.#.#.#.#.#.#.###.###.#.###.#######.#.#.#v#.#.#.#####.#.#.#.#.###########.#.#####.#.###.#.#.#.#v#.###.#
+#.........#.............#...#...#.#...#.#.#.#.#.#.#...#.###...#...#.......#...#.#...#...#...#.#.#.#.....#...#...#...#...#.#...#...#.>.#...#.#
+#.#######.#.###########.#.#######.#####.#.#.#.#.#.###.#.#######.###.###########.#######.#.###.#.#.#####v#.#.#.#####.#.###.#.#########v###.#.#
+#.....#...#...........#...#.....#...###.#.#.#.#.#.....#.#...#...###...........#.....#...#...#.#.#...#.>.>.#...#...#.#.#...#...###...#...#.#.#
+#####.#.#############.#####.###.###.###.#.#.#.#.#######.#.#.#.###############.#####.#.#####.#.#.###.#.#v#######.#.#.#.#.#####.###.#.###.#.#.#
+#.....#.#...#.........#...#...#.#...#...#.#.#.#.....#...#.#.#.....#...#.......#.....#.#...#.#...#...#.#.#...###.#.#.#.#...#...#...#.....#...#
+#.#####.#.#.#.#########.#.###.#.#.###.###.#.#.#####.#.###.#.#####v#.#.#.#######.#####.#.#.#.#####.###.#.#.#.###.#.#.#.###.#.###.#############
+#.....#.#.#.#.......###.#...#.#.#...#...#.#.#.#...#.#...#.#.#...>.>.#.#...#...#.....#.#.#...#.....#...#...#...#.#.#...###...###.............#
+#####.#.#.#.#######v###.###.#.#.###.###.#.#.#.#.#.#.###.#.#.#.###v###.###.#.#.#####.#.#.#####.#####.#########.#.#.#########################.#
+#.....#...#.......#.>.#.#...#.#.#...#...#.#.#...#.#.#...#.#...#...###...#.#.#.......#...#.....#...#.#.......#...#.....#.....................#
+#.###############.#v#.#.#.###.#.#v###.###.#.#####.#.#.###.#####.#######.#.#.#############.#####.#.#.#.#####.#########.#.#####################
+#.#.....#...#...#...#...#.#...#.>.>.#.#...#.....#...#.#...#...#.......#...#...........###.#...#.#.#.#.....#...........#.....................#
+#.#.###.#.#.#.#.#########.#.#####v#.#.#.#######.#####.#.###.#.#######.###############.###.#.#.#.#.#.#####.#################################.#
+#...#...#.#.#.#.........#.#...#...#...#...#...#.#.....#.#...#.........###...........#...#.#.#.#.#.#.#...#...............###...#.............#
+#####.###.#.#.#########.#.###.#.#########.#.#.#.#.#####.#.###############.#########.###.#.#.#.#.#.#.#.#.###############.###.#.#.#############
+#...#.....#.#.#.........#.#...#...#.....#.#.#...#.#.....#...............#.........#.....#...#.#.#...#.#.................#...#.#.............#
+#.#.#######.#.#.#########.#.#####.#.###.#.#.#####.#.###################.#########.###########.#.#####.###################.###.#############.#
+#.#.......#...#.........#.#.#.....#.#...#.#.....#...#.........#.....#...#.........#.........#...#...#...........#...#...#...#.#.....#...#...#
+#.#######.#############.#.#.#.#####.#.###.#####.#####.#######.#.###.#.###.#########.#######.#####.#.###########.#.#.#.#.###.#.#.###.#.#.#.###
+#.......#.#...#.........#.#.#...#...#...#.......#...#.......#.#...#.#...#.........#.#...#...###...#.#...#...###...#...#...#.#...###...#.#...#
+#######.#.#.#.#.#########.#.###.#.#####.#########.#.#######.#.###.#.###.#########.#.#.#.#.#####.###.#.#.#.#.#############.#.###########.###.#
+#.......#...#...#.......#.#.###...#...#...#.....#.#...#.....#.....#...#.#.....#...#.#.#...#...#...#...#...#.......#.......#.....#...###.....#
+#.###############.#####.#.#.#######.#.###.#.###.#.###.#.#############.#.#.###.#.###.#.#####.#.###.###############.#.###########v#.#.#########
+#.................#.....#.#.#.......#.....#.#...#.#...#.........#...#...#...#.#.....#...#...#.###...............#...#.....###.>.#.#.........#
+###################.#####.#.#.#############.#.###.#.###########.#.#.#######.#.#########.#.###.#################.#####.###.###.#v#.#########.#
+#...................#...#...#...........###.#.###.#.#...###.....#.#.....#...#.#...#.....#...#.#...#...#.....###...###.#...#...#...#.........#
+#.###################.#.###############.###.#.###.#.#.#.###v#####.#####.#.###.#.#.#.#######.#.#.#.#.#.#.###.#####.###.#.###.#######.#########
+#...#...............#.#.###...#...#.....#...#...#.#.#.#.#.>.>.....#.....#...#...#.#.#...###.#.#.#.#.#.#...#.###...#...#.#...#.......###...###
+###.#.#############.#.#.###.#.#.#.#.#####.#####.#.#.#.#.#.#v#######.#######.#####.#.#.#.###.#.#.#.#.#.###.#.###.###.###.#.###.#########.#.###
+#...#.#...........#.#.#.....#.#.#.#.....#.....#.#.#...#...#.###.....###...#.....#...#.#...#.#.#.#.#.#.#...#.#...###...#.#...#...#.....#.#.###
+#.###.#.#########.#.#.#######.#.#.#####.#####.#.#.#########.###.#######.#.#####.#####.###.#.#.#.#.#.#.#.###.#.#######.#.###.###.#.###.#.#.###
+#...#.#.........#...#.#.......#.#.#...#.#...#.#.#.###...###...#...#...#.#.#...#...###...#.#.#.#.#.#.#.#.#...#...###...#.....###.#...#...#...#
+###.#.#########.#####.#.#######.#.#.#.#v#.#.#.#.#.###.#.#####.###.#.#.#.#.#.#.###.#####.#.#.#.#.#.#.#.#.#.#####v###.###########.###.#######.#
+###...#####...#.#...#.#.#...#...#.#.#.>.>.#...#...#...#.......###.#.#.#.#.#.#.#...#...#.#.#.#.#.#.#.#.#.#.#...>.>.#.........#...#...###.....#
+###########.#.#.#.#v#.#.#.#.#.###.#.###v###########.#############.#.#.#.#.#.#.#v###.#.#.#.#.#.#.#.#.#.#.#.#.###v#.#########.#.###.#####.#####
+#...........#.#...#.>.#...#.#.###...###.#...#.....#...........###.#.#...#.#.#.>.>...#.#.#.#.#.#.#.#.#.#.#...#...#...#.....#.#...#.#.....#...#
+#.###########.#####v#######.#.#########.#.#.#.###.###########.###.#.#####.#.###v#####.#.#.#.#.#.#.#.#.#.#####.#####.#.###.#.###.#.#.#####.#.#
+#...........#...###.....#...#...#.......#.#...#...#...#.......#...#.....#...###...###.#.#.#.#.#.#.#.#...#.....#...#.#...#.#...#...#.......#.#
+###########.###.#######.#.#####.#.#######.#####.###.#.#.#######.#######.#########.###.#.#.#.#.#.#.#.#####.#####.#.#.###.#.###.#############.#
+###...#...#...#.#...#...#.......#.........#...#...#.#...#...###.#...#...#...#...#...#.#.#.#.#.#.#.#.#.....#.....#.#.....#.#...#...#.........#
+###.#.#.#.###.#.#.#.#.#####################.#.###.#.#####.#.###.#.#.#.###.#.#.#.###.#.#.#.#.#.#.#.#.#.#####.#####.#######.#.###.#.#.#########
+#...#...#.....#...#...###.................#.#.....#.......#...#.#.#...###.#.#.#.#...#...#...#.#.#.#.#...#...#...#...#...#...#...#.#.........#
+#.#######################.###############.#.#################.#.#.#######.#.#.#.#.###########.#.#.#.###.#.###.#.###.#.#.#####.###.#########.#
+#...#...............#...#...............#...#.....#...#.......#...#...###.#.#.#.#...........#.#.#...###.#.#...#.....#.#.#...#...#.#.........#
+###.#.#############.#.#.###############.#####.###.#.#.#.###########.#.###.#.#.#.###########.#.#.#######.#.#.#########.#.#.#.###.#.#.#########
+###...#####...#...#.#.#.#...#.....#...#.....#...#...#.#.#...#.......#.#...#.#.#.#...........#.#...#...#...#...........#.#.#...#.#.#.#.......#
+###########.#.#.#.#.#.#.#.#.#.###.#.#.#####.###.#####.#.#.#.#.#######.#.###.#.#.#.###########.###.#.#.#################.#.###.#.#.#.#.#####.#
+#...###.....#...#...#.#.#.#.#.#...#.#.#.....#...#.....#...#.#...#.....#.#...#.#.#.#.........#.#...#.#.#...#.......#.....#.#...#.#.#...#...#.#
+#.#.###.#############.#.#.#.#.#.###.#.#v#####.###.#########.###.#.#####.#.###.#.#v#.#######.#.#.###.#.#.#.#.#####.#.#####.#.###.#.#####v#.#.#
+#.#.....#...#...###...#.#.#.#.#.#...#.>.>...#...#...#...#...#...#...#...#...#.#.>.>.#.......#...#...#...#.#...###...###...#.#...#...#.>.#.#.#
+#.#######.#.#.#.###.###.#.#.#.#.#.#########.###.###.#.#.#.###.#####.#.#####.#.#######.###########.#######.###.#########.###.#.#####.#.#v#.#.#
+#.#.......#...#.#...###.#.#.#.#.#.......###...#.#...#.#.#...#.#.....#.....#.#.###...#.....#...###.......#...#.#...###...###.#.#.....#.#.#...#
+#.#.###########.#.#####.#.#.#.#.#######.#####.#.#.###.#.###v#.#.#########.#.#.###.#.#####.#.#.#########.###.#.#.#.###.#####.#.#.#####.#.#####
+#.#.#...........#.....#.#.#.#.#...#...#...###.#.#...#.#.#.>.>.#...#...#...#.#.#...#.......#.#.#...###...#...#.#.#.#...#####.#.#.......#.....#
+#.#.#.###############.#.#.#.#.###.#.#.###.###.#.###.#.#.#.#######.#.#.#.###.#.#.###########.#.#.#.###.###.###.#.#.#.#######.#.#############.#
+#...#...........#.....#...#...#...#.#...#.#...#.#...#.#.#.......#...#.#...#.#.#.#.......#...#.#.#.#...#...#...#.#.#.......#.#.#.............#
+###############.#.#############.###.###.#.#.###.#.###.#.#######.#####.###.#.#.#.#.#####.#.###.#.#.#.###.###.###.#.#######.#.#.#.#############
+#...............#.............#...#...#.#.#...#.#...#.#...#...#.#.....#...#...#.#.#.....#...#.#.#.#...#.###...#.#.#.......#...#...#...#...###
+#.###########################.###.###.#.#.###.#.###.#.###.#.#.#.#.#####.#######.#.#.#######.#.#.#.###.#.#####v#.#.#.#############.#.#.#.#.###
+#.#...#...#.....#...#...#...#.#...#...#.#.#...#...#.#...#.#.#.#.#.....#.....#...#.#.#.....#.#.#.#...#.#...#.>.>.#.#.........#.....#.#.#.#...#
+#.#.#.#.#.#.###.#.#.#.#.#.#.#.#.###.###.#.#.#####.#.###.#.#.#.#.#####.#####.#.###.#.#.###.#.#.#.###.#.###.#.#####.#########.#.#####.#.#.###.#
+#...#...#...###...#...#...#...#.....###...#.......#.....#...#...#####.......#.....#...###...#...###...###...#####...........#.......#...###.#
+###########################################################################################################################################.#

+ 23 - 0
Day23/inputs/sample1.txt

@@ -0,0 +1,23 @@
+#.#####################
+#.......#########...###
+#######.#########.#.###
+###.....#.>.>.###.#.###
+###v#####.#v#.###.#.###
+###.>...#.#.#.....#...#
+###v###.#.#.#########.#
+###...#.#.#.......#...#
+#####.#.#.#######.#.###
+#.....#.#.#.......#...#
+#.#####.#.#.#########v#
+#.#...#...#...###...>.#
+#.#.#v#######v###.###v#
+#...#.>.#...>.>.#.###.#
+#####v#.#.###v#.#.###.#
+#.....#...#...#.#.#...#
+#.#########.###.#.#.###
+#...###...#...#...#.###
+###.###.#.###v#####v###
+#...#...#.#.>.>.#.>.###
+#.###.###.#.###.#.#v###
+#.....###...###...#...#
+#####################.#