-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
126 lines (116 loc) · 3.71 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
namespace AdventOfCode2022
{
internal class Program
{
static void Main(string[] args)
{
string[] input = File.ReadAllLines(@"C:\Users\pette\Documents\AoC15b.txt");
List<Point> SBList = new List<Point>();
foreach (string s in input)
{
if (s != "")
{
string[] temp = s.Split(" ");
string[] Sx = temp[2].Split("=");
string[] Sy = temp[3].Split("=");
SBList.Add(new Point(Convert.ToInt32(Sx[1].Remove(Sx[1].Length - 1)),
Convert.ToInt32(Sy[1].Remove(Sy[1].Length - 1)), 'S'));
string[] Bx = temp[8].Split("=");
string[] By = temp[9].Split("=");
SBList.Add(new Point(Convert.ToInt32(Bx[1].Remove(Bx[1].Length - 1)),
Convert.ToInt32(By[1]), 'B'));
}
}
//foreach (Point p in SBList)
//{
// Console.WriteLine($"{p.x} {p.y} {p.img}");
//}
//Console.ReadKey();
// Create point map.
Point[,] map = new Point[100, 100];
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
map[i, j] = new Point(j, i, '.');
}
}
//foreach (Point p in map)
//{
// Console.WriteLine(p.x + " " + p.y + " " + p.img);
//}
foreach (Point p in SBList)
{
foreach (Point mp in map)
{
if (p.x + 20 == mp.x && p.y + 20 == mp.y)
{
mp.img = p.img;
}
}
}
for (int i = 0; i < SBList.Count; i += 2)
{
int xdif = Diff(SBList[i].x, SBList[i + 1].x);
int ydif = Diff(SBList[i].y, SBList[i + 1].y);
int Sx = SBList[i].x + 20;
int Sy = SBList[i].y + 20;
int dist = xdif + ydif;
for (int j = 0; j < dist; j++)
{
for (int k = dist - j; k > 0; k--)
{
if (map[Sy + k, Sx + j].img == '.')
{
map[Sy + k, Sx + j].img = '#';
}
if (map[Sy - k, Sx - j].img == '.')
{
map[Sy - k, Sx - j].img = '#';
}
if (map[Sy + j, Sx - k].img == '.')
{
map[Sy + j, Sx - k].img = '#';
}
if (map[Sy - j, Sx + k].img == '.')
{
map[Sy - j, Sx + k].img = '#';
}
}
}
}
// Print map.
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
Console.Write(map[i, j].img);
}
Console.WriteLine();
}
}
public static int Diff(int a, int b)
{
if (a > b)
{
return a - b;
}
else
{
return b - a;
}
}
}
public class Point
{
public int x;
public int y;
public char img;
public Point(int X, int Y, char Img)
{
x = X;
y = Y;
img = Img;
}
}
}