Skip to content

Commit

Permalink
add build/test action; minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
gereons committed Dec 4, 2023
1 parent 540bff1 commit fadfd05
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions Sources/Day02/Day02.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import AoCTools

struct Game {
private struct Game {
let id: Int
let sets: [Set]

Expand Down Expand Up @@ -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) }
Expand Down
8 changes: 4 additions & 4 deletions Sources/Day03/Day03.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import AoCTools

struct Number: Hashable {
private struct Number: Hashable {
let value: Int
let start: Point
let length: Int
Expand All @@ -27,9 +27,9 @@ struct Number: Hashable {
}

final class Day03: AOCDay {
let symbols: Set<Point>
let gears: Set<Point>
let numbers: Set<Number>
private let symbols: Set<Point>
private let gears: Set<Point>
private let numbers: Set<Number>

init(input: String) {
var symbols = Set<Point>()
Expand Down
21 changes: 8 additions & 13 deletions Sources/Day04/Day04.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@
//

import AoCTools
import Foundation

struct Card {
private struct Card {
let id: Int
let winners: Set<Int>
let numbers: Set<Int>
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 {
Expand All @@ -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) }
Expand All @@ -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]
}
}
Expand Down

0 comments on commit fadfd05

Please sign in to comment.