diff --git a/Year2024/Sources/Day01.swift b/Year2024/Sources/Day01.swift index 34cb51e..0d6e082 100644 --- a/Year2024/Sources/Day01.swift +++ b/Year2024/Sources/Day01.swift @@ -20,7 +20,15 @@ public enum Day01: Day { } public static func part2(_ input: Input) throws -> Int { - 0 + let rows = try input.lines + .map { + let values = $0.split(whereSeparator:(\.isWhitespace)) + return try (Int(values.first.unwrapped), Int(values.last.unwrapped)) + } + let columns = rotate(rows) + let lhs = columns.0 + let rhs = columns.1 + return lhs.map { $0 * rhs.count(of: $0) }.sum } } diff --git a/Year2024/Tests/Day01Tests.swift b/Year2024/Tests/Day01Tests.swift index a18ff03..9fd4cc2 100644 --- a/Year2024/Tests/Day01Tests.swift +++ b/Year2024/Tests/Day01Tests.swift @@ -22,11 +22,18 @@ final class Day01Tests: XCTestCase { } func testPart2Examples() throws { - XCTAssertEqual(try Day01.part2([]), 0) + XCTAssertEqual(try Day01.part2([ + "3 4", + "4 3", + "2 5", + "1 3", + "3 9", + "3 3", + ]), 31) } func testPart2Puzzle() throws { let input = try Bundle.module.input(named: "Day01") - XCTAssertEqual(try Day01.part2(input), 0) + XCTAssertEqual(try Day01.part2(input), 23741109) } }