-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day6.cs
23 lines (18 loc) · 821 Bytes
/
Day6.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Collections.Generic;
using System.IO;
class Day6 {
public static int Solution1() => Solution(new HashSet<char>(), (answers, person) => answers.UnionWith(person));
public static int Solution2() => Solution(new HashSet<char>("abcdefghijklmnopqrstuvwxyz"), (answers, person) => answers.IntersectWith(person));
static int Solution(HashSet<char> startSet, Action<HashSet<char>, string> setOp) {
int answer = 0;
foreach (string group in File.ReadAllText("input6.txt").Split(new[] { "\n\n" }, StringSplitOptions.None)) {
HashSet<char> answers = new HashSet<char>(startSet);
foreach (string person in group.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)) {
setOp(answers, person);
}
answer += answers.Count;
}
return answer;
}
}