Skip to content

Commit 2460e37

Browse files
committed
Add 2024, day 3, part 1
1 parent 12c4f29 commit 2460e37

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

Year2024/Sources/Day03.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
import Advent
3+
import RegexBuilder
4+
5+
public enum Day03: Day {
6+
7+
public static let title = "Mull It Over"
8+
9+
private static let regex = Regex {
10+
"mul("
11+
TryCapture.integer
12+
","
13+
TryCapture.integer
14+
")"
15+
}
16+
17+
public static func part1(_ input: Input) throws -> Int {
18+
input.string.matches(of: regex).map { match in
19+
match.output.1 * match.output.2
20+
}
21+
.sum
22+
}
23+
24+
public static func part2(_ input: Input) throws -> Int {
25+
0
26+
}
27+
}

Year2024/Tests/Day03Tests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
import Advent
3+
import Year2024
4+
import XCTest
5+
6+
final class Day03Tests: XCTestCase {
7+
8+
func testPart1Examples() throws {
9+
XCTAssertEqual(try Day03.part1([
10+
"xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"
11+
]), 161)
12+
}
13+
14+
func testPart1Puzzle() throws {
15+
let input = try Bundle.module.input(named: "Day03")
16+
XCTAssertEqual(try Day03.part1(input), 179571322)
17+
}
18+
19+
func testPart2Examples() throws {
20+
XCTAssertEqual(try Day03.part2([]), 0)
21+
}
22+
23+
func testPart2Puzzle() throws {
24+
let input = try Bundle.module.input(named: "Day03")
25+
XCTAssertEqual(try Day03.part2(input), 0)
26+
}
27+
}

0 commit comments

Comments
 (0)