-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 10.txt
119 lines (108 loc) · 3.3 KB
/
Day 10.txt
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
internal class Program
{
static void Main(string[] args)
{
string[] input = File.ReadAllLines(@"C:/Users/pette/Documents/AoC10.txt");
List<Action> actionList = new List<Action>();
foreach (string s in input)
{
if (s != "noop")
{
string[] temp = s.Split(" ");
actionList.Add(new Action(temp[0], Convert.ToInt32(temp[1])));
}
else
{
actionList.Add(new Action(s, 0));
}
}
int spritePos = 0;
int writePos = 0;
List<char> screenOutput = new List<char>();
foreach (Action ac in actionList)
{
if (ac.action == "noop")
{
screenOutput.Add(CheckSprite(writePos, spritePos));
writePos++;
if (writePos == 40)
{
writePos = 0;
}
}
else
{
screenOutput.Add(CheckSprite(writePos, spritePos));
writePos++;
if (writePos == 40)
{
writePos = 0;
}
screenOutput.Add(CheckSprite(writePos, spritePos));
writePos++;
if (writePos == 40)
{
writePos = 0;
}
spritePos += ac.value;
}
}
for (int i = 0; i < 240; i++)
{
if (i == 40 || i == 80 || i == 120 || i == 160 || i == 200 || i == 240)
{
Console.WriteLine();
}
Console.Write(screenOutput[i]);
}
//// Solution part 1
//int x = 1;
//int cycles = 0;
//List<int> cycleList = new List<int>();
//foreach (Action ac in actionList)
//{
// if (ac.action == "noop")
// {
// cycles++;
// cycleList.Add(x);
// }
// else
// {
// cycles++;
// cycleList.Add(x);
// cycles++;
// cycleList.Add(x);
// x += ac.value;
// }
//}
//int a = cycleList[19] * 20;
//int b = cycleList[59] * 60;
//int c = cycleList[99] * 100;
//int d = cycleList[139] * 140;
//int e = cycleList[179] * 180;
//int f = cycleList[219] * 220;
//int sum = a + b + c + d + e + f;
//Console.WriteLine(sum);
}
public static char CheckSprite(int a, int x)
{
if (a == x || a == x + 2 || a == x + 1)
{
return '#';
}
else
{
return '.';
}
}
}
public class Action
{
public string action;
public int value;
public Action(string s, int i)
{
action = s;
value = i;
}
}