-
Notifications
You must be signed in to change notification settings - Fork 0
/
11-2.linq
53 lines (49 loc) · 1.5 KB
/
11-2.linq
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
<Query Kind="Program" />
void Main()
{
int serialNumber = 6878;
int[,] grid = new int[300, 300];
for (int x = 1; x <= 300; x++)
{
for (int y = 1; y <= 300; y++)
{
int rackId = x + 10;
int powerLevel = rackId * y;
powerLevel += serialNumber;
powerLevel *= rackId;
string powerLevelString = powerLevel.ToString();
powerLevel = powerLevel >= 100 ? int.Parse(powerLevelString[powerLevelString.Length - 3].ToString()) : 0;
powerLevel -= 5;
grid[(x - 1), (y - 1)] = powerLevel;
}
}
int topSize = 1;
int topPower = 0;
int topX = 0;
int topY = 0;
for (int size = 1; size <= 300; size++)
{
for (int x = 1; x <= 301 - size; x++)
{
for (int y = 1; y <= 301 - size; y++)
{
int currentPower = 0;
for (int x2 = 1; x2 <= size; x2++)
{
for (int y2 = 1; y2 <= size; y2++)
{
currentPower += grid[x - 2 + x2, y - 2 + y2];
}
}
if (currentPower > topPower)
{
topPower = currentPower;
topX = x;
topY = y;
topSize = size;
}
}
}
}
string.Format("{0},{1},{2}", topX, topY, topSize).Dump();
}