-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask19.cs
54 lines (45 loc) · 1.06 KB
/
Task19.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
using FluentAssertions;
using NUnit.Framework;
namespace AoC_2024;
[TestFixture]
public class Task19
{
[Test]
[TestCase(@"r, wr, b, g, bwu, rb, gb, br
brwrr
bggr
gbbr
rrbgbr
ubwu
bwurrg
brgr
bbrgwb", 6)]
[TestCase(@"Task19.txt", 315)]
public void Task(string input, int expected)
{
input = File.Exists(input) ? File.ReadAllText(input) : input;
var stripes = input.SplitLines().First().SplitEmpty(", ");
var result = 0;
foreach (var line in input.SplitLines().Skip(1))
{
if (IsPossible(line, stripes))
{
result++;
}
}
result.Should().Be(expected);
}
private bool IsPossible(string line, string[] stripes)
{
foreach (var stripe in stripes)
{
if (line == stripe) return true;
if (line.StartsWith(stripe))
{
var newLine = line.Substring(stripe.Length);
if (IsPossible(newLine, stripes)) return true;
}
}
return false;
}
}