-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day5.cs
53 lines (43 loc) · 870 Bytes
/
Day5.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
using System.Collections.Generic;
using System.IO;
class Day5 {
public static int Solution1() {
int max = 0;
foreach (int id in GetIDs()) {
if (id > max) {
max = id;
}
}
return max;
}
public static int Solution2() {
int min = int.MaxValue;
int max = 0;
int sum = 0;
foreach (int id in GetIDs()) {
if (id > max) {
max = id;
} else if (id < min) {
min = id;
}
sum += id;
}
return (max + min) * (max - min + 1) / 2 - sum;
}
static IEnumerable<int> GetIDs() {
foreach (string seat in File.ReadLines("input5.txt")) {
int id = 0;
for (int i = 0; i < 7; i++) {
if (seat[i] == 'B') {
id |= 1 << (9 - i);
}
}
for (int i = 7; i < 10; i++) {
if (seat[i] == 'R') {
id |= 1 << (9 - i);
}
}
yield return id;
}
}
}