Skip to content

Commit d672fb6

Browse files
committed
day19
1 parent d6266c3 commit d672fb6

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

Sources/AdventOfCode.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ let allChallenges: [any AdventDay] = [
1717
// Day13(),
1818
// Day14(),
1919
// Day15(),
20-
Day17()
20+
// Day17(),
21+
Day19()
2122
]
2223

2324
@main

Sources/Day19.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Algorithms
2+
3+
struct Day19: AdventDay {
4+
var data: String
5+
6+
func part1() throws -> Int {
7+
let parts = data.trimmed().split(separator: "\n\n")
8+
let words =
9+
"^(\(parts[0].split(separator: ",").map { "(\($0.trimmed()))" }.joined(separator: "|")))*$"
10+
let regex = try Regex(words)
11+
12+
var count = 0
13+
for design in parts[1].lines() {
14+
if (try? regex.wholeMatch(in: design)) != nil {
15+
count += 1
16+
}
17+
}
18+
return count
19+
}
20+
21+
func part2() -> Int {
22+
0
23+
}
24+
}

Tests/Day19.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Testing
2+
3+
@testable import aoc
4+
5+
@Suite("Day19")
6+
struct Day19Tests {
7+
let testData = """
8+
r, wr, b, g, bwu, rb, gb, br
9+
10+
brwrr
11+
bggr
12+
gbbr
13+
rrbgbr
14+
ubwu
15+
bwurrg
16+
brgr
17+
bbrgwb
18+
"""
19+
20+
@Test("part1")
21+
func testPart1() async throws {
22+
let challenge = Day19(data: testData)
23+
#expect(try challenge.part1() == 6)
24+
}
25+
26+
@Test("part2")
27+
func testPart2() async throws {
28+
let challenge = Day19(data: testData)
29+
#expect(challenge.part2() == 0)
30+
}
31+
}

0 commit comments

Comments
 (0)