-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
58 lines (49 loc) · 1.9 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
using System;
namespace Day4
{
class Program
{
static void Main()
{
int min = 136760;
int max = 595730;
int count0 = 0;
int count1 = 0;
for (int i = min; i <= max; i++)
{
string num = i.ToString();
bool adjacent0 = false;
for (int c = 1; c < num.Length; c++)
{
if (num[c - 1] == num[c])
{
adjacent0 = true;
}
if (Convert.ToInt32(num[c]) < Convert.ToInt32(num[c - 1]))
{
break;
}
if (c == num.Length - 1 && adjacent0)
{
// Console.WriteLine(num);
count0++;
}
}
bool adjacent1 = (num[0] == num[1] && num[1] != num[2]) || (num[0] != num[1] && num[1] == num[2] && num[2] != num[3]) || (num[1] != num[2] && num[2] == num[3] && num[3] != num[4]) || (num[2] != num[3] && num[3] == num[4] && num[4] != num[5]) || (num[3] != num[4] && num[4] == num[5]);
bool noDecrease1 = (Convert.ToInt32(num[5]) >= Convert.ToInt32(num[4]) && Convert.ToInt32(num[4]) >= Convert.ToInt32(num[3]) && Convert.ToInt32(num[3]) >= Convert.ToInt32(num[2]) && Convert.ToInt32(num[2]) >= Convert.ToInt32(num[1]) && Convert.ToInt32(num[1]) >= Convert.ToInt32(num[0]));
if (!noDecrease1)
{
continue;
}
if (adjacent1)
{
// Console.WriteLine(num);
count1++;
}
}
Console.WriteLine($"part 1: {count0}");
Console.WriteLine($"part 2: {count1}");
Console.ReadKey();
}
}
}