diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..cba40a2 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,20 @@ +name: Build + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + DEVELOPER_DIR: /Applications/Xcode_15.0.1.app/Contents/Developer + +jobs: + build: + runs-on: macos-13 + steps: + - uses: actions/checkout@v4 + - name: Build + run: swift build + - name: Run tests + run: swift test diff --git a/Sources/Day02/Day02.swift b/Sources/Day02/Day02.swift index 2b700d7..e47951b 100644 --- a/Sources/Day02/Day02.swift +++ b/Sources/Day02/Day02.swift @@ -6,7 +6,7 @@ import AoCTools -struct Game { +private struct Game { let id: Int let sets: [Set] @@ -63,7 +63,7 @@ struct Game { } final class Day02: AOCDay { - let games: [Game] + private let games: [Game] init(input: String) { games = input.lines.map { Game($0) } diff --git a/Sources/Day03/Day03.swift b/Sources/Day03/Day03.swift index a691d72..4639e7e 100644 --- a/Sources/Day03/Day03.swift +++ b/Sources/Day03/Day03.swift @@ -6,7 +6,7 @@ import AoCTools -struct Number: Hashable { +private struct Number: Hashable { let value: Int let start: Point let length: Int @@ -27,9 +27,9 @@ struct Number: Hashable { } final class Day03: AOCDay { - let symbols: Set - let gears: Set - let numbers: Set + private let symbols: Set + private let gears: Set + private let numbers: Set init(input: String) { var symbols = Set() diff --git a/Sources/Day04/Day04.swift b/Sources/Day04/Day04.swift index 77b520e..d18f1cb 100644 --- a/Sources/Day04/Day04.swift +++ b/Sources/Day04/Day04.swift @@ -5,24 +5,19 @@ // import AoCTools -import Foundation -struct Card { +private struct Card { let id: Int - let winners: Set - let numbers: Set + let matches: Int init(_ string: String) { // Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 let parts = string.components(separatedBy: ":") self.id = parts[0].allInts().first! - let numbers = parts[1].components(separatedBy: "|") - self.winners = Set(numbers[0].allInts()) - self.numbers = Set(numbers[1].allInts()) - } - - var matches: Int { - numbers.intersection(winners).count + let nums = parts[1].components(separatedBy: "|") + let winners = Set(nums[0].allInts()) + let numbers = Set(nums[1].allInts()) + matches = numbers.intersection(winners).count } var points: Int { @@ -31,7 +26,7 @@ struct Card { } final class Day04: AOCDay { - let cards: [Card] + private let cards: [Card] init(input: String) { cards = input.lines.map { Card($0) } @@ -46,7 +41,7 @@ final class Day04: AOCDay { copies[0] = 0 for card in cards where card.matches > 0 { - for i in card.id + 1 ... card.id + card.matches where i < copies.count + 1 { + for i in card.id + 1 ... card.id + card.matches { copies[i] += copies[card.id] } }