-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
49 lines (41 loc) · 1.09 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
using CodeAdvent;
foreach (var (clues, candidates) in new[] { NumberExample(), ColorExample() })
{
var solutions = candidates
.Where(x => clues.All(clue => clue.Matches(x)));
Console.WriteLine("Solution(s): {0}", string.Join(", ", solutions));
}
(Clue[], IEnumerable<string>) NumberExample()
{
var clues = new Clue[]
{
new("682", 1, 0),
new("614", 0, 1),
new("206", 0, 2),
new("738", 0, 0),
new("780", 0, 1),
};
var candidates = Enumerable
.Range(0, 1000)
.Select(x => $"{x:D3}");
return (clues, candidates);
}
(Clue[], IEnumerable<string>) ColorExample()
{
var clues = new Clue[]
{
new("RBGY", 1, 1),
new("POGY", 1, 0),
new("GYGY", 0, 0),
new("RBPP", 1, 1),
new("ROBO", 2, 2),
};
const string colors = "RBGYPO";
var candidates =
from c1 in colors
from c2 in colors
from c3 in colors
from c4 in colors
select $"{c1}{c2}{c3}{c4}";
return (clues, candidates);
}