Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #load "xunit"
- #load "AOC Connector"
- #load "AOC 2d Array"
- void Main()
- {
- RunTests(); // Call RunTests() or press Alt+Shift+T to initiate testing.
- //get aoc data
- var aoc = new AdventOfCode(2020, 6);
- //solve A
- aoc.SubmitAnswer(SolveA(aoc.InputLines), Part.A);
- //solve B
- aoc.SubmitAnswer(SolveB(aoc.InputLines), Part.B);
- }
- public int SolveA(string[] input)
- {
- return input.SplitInputOnDoubleBreak()
- .Select(x => x.Where(y => y != ' ') //grab all items not whitespace
- .Distinct().Count() //count the unique items
- ).Sum(); //total
- }
- public int SolveB(string[] input)
- {
- return input.SplitInputOnDoubleBreak()
- .Sum(x =>
- (
- x.Replace(" ", "") //remove whitespaces
- .GroupBy(y => y) //count each answer
- .Count(y => y.Count() == x.Count(y => y == ' ') + 1) //count the whitespace in in the original and + 1 is people count,
- ));
- }
- #region private::Tests
- #region test data
- string[] testData = new []
- {
- "abc",
- "",
- "a",
- "b",
- "c",
- "",
- "ab",
- "ac",
- "",
- "a",
- "a",
- "a",
- "a",
- "",
- "b",
- };
- #endregion
- //tests
- [Fact] void TestA() => Assert.Equal(11, SolveA(testData));
- [Fact] void TestB() => Assert.Equal(6, SolveB(testData));
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment