using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace Kalender { internal class day9_part1 { static string file = "../../../files/day9.txt"; static string[] lines = File.ReadAllLines(file); static int rows = 20; static int column = 20; static string[,] field = new string[rows, column]; static public void create2DArray() { for (int i = 0; i < rows; i++) { for (int j = 0; j < column; j++) { field[i, j] = "[ ]"; } } } static public void fieldPrint() { //Start int counter = 0; for (int i = 0; i < rows; i++) { for (var j = 0; j < column; j++) { Console.Write(field[i, j]); if (field[i, j] == "[#]") { counter++; } } Console.Write("\n"); } Console.WriteLine($"Tails {counter}"); } static public void moveTail(int xx, int yy, char direction, int steps) { int x = xx; int y = yy; field[x, y] = "[#]"; for (int i = 0; i < steps; i++) { switch (direction) { case 'R': y ++; break; case 'L': y --; break; case 'U': x--; break; case 'D': x++; break; } field[x, y] = "[#]"; } } static public void day9_01() { create2DArray(); int currentPosx = rows /2; int currentPosy = column / 2; int step = 0; field[currentPosx, currentPosy] = "[S]"; foreach (var line in lines) { step = Convert.ToInt16(line.Substring(2)); moveTail(currentPosx, currentPosy, line[0], step); int headx = 0; int heady = 0; switch (line[0]) { case 'R': heady = step; currentPosy += heady; break; case 'L': heady = step; currentPosy -= heady; break; case 'U': headx = step; currentPosx -= headx; break; case 'D': headx = step; currentPosx += headx; break; } field[currentPosx, currentPosy] = "[H]"; } fieldPrint(); } } class day9_part2 { } }