-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task8Tests.cs
57 lines (50 loc) · 1.85 KB
/
Task8Tests.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
using adventofcode_2021.Task8;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xunit;
namespace adventofcode_2021.Tests
{
public class Task8Tests
{
[Fact]
public void Task8_RealExample_Correct()
{
var (numbers, boards, boardsDict) = ReadFileAsync(Path.Combine("Task8", "Data.txt"));
Assert.Equal(1924, Solution.Function(numbers, boards, boardsDict));
}
private (List<int>, List<int[,]>, List<Dictionary<int, (int, int)>>) ReadFileAsync(string fileName)
{
var lines = File.ReadAllLines(fileName);
var bingoNumbers = lines.First().Split(',').Select(int.Parse).ToList();
var bingoBoards = new List<int[,]>();
var bingoBoardsDict = new List<Dictionary<int, (int, int)>>();
var skipLines = 2;
var bingoSize = 5;
while (skipLines < lines.Length)
{
var bingoItem = new int[5, 5];
Dictionary<int, (int, int)> bingoItemDict = new();
lines
.Skip(skipLines)
.Take(bingoSize)
.Aggregate(0, (si, nexts) =>
{
nexts.Split(' ', System.StringSplitOptions.RemoveEmptyEntries)
.Aggregate(0, (ni, nextn) =>
{
var val = int.Parse(nextn);
bingoItem[si, ni] = val;
bingoItemDict[val] = (si, ni);
return ni + 1;
});
return si + 1;
});
bingoBoards.Add(bingoItem);
bingoBoardsDict.Add(bingoItemDict);
skipLines += (bingoSize + 1);
}
return (bingoNumbers, bingoBoards, bingoBoardsDict);
}
}
}