Skip to content

Commit

Permalink
adopt 2024 structure
Browse files Browse the repository at this point in the history
  • Loading branch information
gereons committed Jan 2, 2025
1 parent 1bb4e51 commit d304d78
Show file tree
Hide file tree
Showing 57 changed files with 94 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
/*.xcodeproj
.swiftpm
.aoc-session
Sources/Day*/*Input.swift
Sources/Inputs/*Input.swift
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2023 Gereon Steffens
Copyright 2025 Gereon Steffens

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
6 changes: 3 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"originHash" : "bade67b167d95524e1f02f49472bc9d2d25b3f835dd08ea689d4c41b80b20d16",
"originHash" : "eb2a557cdbfedc2dcfdf31ab358b5d8840651b725f95588c23af3f3c0a9bc975",
"pins" : [
{
"identity" : "aoctools",
"kind" : "remoteSourceControl",
"location" : "https://github.com/gereons/AoCTools",
"state" : {
"revision" : "d363eb88c324269a870d3fe233dd622c04ba3e60",
"version" : "0.1.6"
"revision" : "a84caf6b4974595bf255b906915767977ed731cb",
"version" : "0.1.7"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let package = Package(
name: "AdventOfCode",
platforms: [ .macOS(.v15) ],
dependencies: [
.package(url: "https://github.com/gereons/AoCTools", from: "0.1.6"),
.package(url: "https://github.com/gereons/AoCTools", from: "0.1.7"),
// .package(path: "../AoCTools"),
],
targets: [
Expand Down
32 changes: 22 additions & 10 deletions Sources/AoC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ enum AdventOfCode {
// assign to eg `.day(1)`, leave as nil to run the puzzle for the current calendar day
static var defaultDay: Day? // = .day(1)

static func main() {
static func main() async {
var day = defaultDay ?? today

if CommandLine.argc > 1 {
let arg = CommandLine.arguments[1]
if let d = Int(arg), 1...25 ~= d {
day = .day(d)
} else if arg == "all" {
day = .all
day = .allSequential
} else if arg == "all-parallel" {
day = .allParallel
}
}

run(day)
await run(day)
Timer.showTotal()
}

Expand All @@ -33,27 +35,37 @@ enum AdventOfCode {
if components.month == 12 && 1...25 ~= day {
return .day(day)
}
return .all
return .allSequential
}

private static func run(_ day: Day) {
private static func run(_ day: Day) async {
switch day {
case .all:
case .allSequential:
for day in days {
day.init(input: day.input).run()
await day.init(input: day.input).run()
}
case .allParallel:
await withTaskGroup(of: Void.self) { group in
for day in days {
group.addTask {
await day.init(input: day.input).run()
}
}
for await _ in group {}
}
case .day(let day):
let day = days[day - 1]
day.init(input: day.input).run()
await day.init(input: day.input).run()
}
}

enum Day {
case all
case allSequential
case allParallel
case day(Int)
}

private static let days: [Runnable.Type] = [
private static let days: [any AdventOfCodeDay.Type] = [
Day01.self, Day02.self, Day03.self, Day04.self, Day05.self,
Day06.self, Day07.self, Day08.self, Day09.self, Day10.self,
Day11.self, Day12.self, Day13.self, Day14.self, Day15.self,
Expand Down
3 changes: 2 additions & 1 deletion Sources/Day01/Day01.swift → Sources/Day01.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import AoCTools

final class Day01: AOCDay {
final class Day01: AdventOfCodeDay {
let title = "Trebuchet?!"
let lines: [String]

init(input: String) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Day02/Day02.swift → Sources/Day02.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ private struct Game {
}
}

final class Day02: AOCDay {
final class Day02: AdventOfCodeDay {
let title = "Cube Conundrum"
private let games: [Game]

init(input: String) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Day03/Day03.swift → Sources/Day03.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ private struct Number: Hashable {
}
}

final class Day03: AOCDay {
final class Day03: AdventOfCodeDay {
let title = "Gear Ratios"
private let symbols: Set<Point>
private let gears: Set<Point>
private let numbers: Set<Number>
Expand Down
3 changes: 2 additions & 1 deletion Sources/Day04/Day04.swift → Sources/Day04.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ private struct Card {
}
}

final class Day04: AOCDay {
final class Day04: AdventOfCodeDay {
let title = "Scratchcards"
private let cards: [Card]

init(input: String) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Day05/Day05.swift → Sources/Day05.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ private struct Range {
var isValid: Bool { from <= to }
}

final class Day05: AOCDay {
final class Day05: AdventOfCodeDay {
let title = "If You Give A Seed A Fertilizer"
private let almanac: Almanac

init(input: String) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Day06/Day06.swift → Sources/Day06.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ private struct Race {
}
}

final class Day06: AOCDay {
final class Day06: AdventOfCodeDay {
let title = "Wait For It"
private let races: [Race]
private let part2Race: Race

Expand Down
3 changes: 2 additions & 1 deletion Sources/Day07/Day07.swift → Sources/Day07.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ extension Hand {
}
}

final class Day07: AOCDay {
final class Day07: AdventOfCodeDay {
let title = "Camel Cards"
private let hands: [Hand]

init(input: String) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Day08/Day08.swift → Sources/Day08.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ private struct Node: Hashable {
}
}

final class Day08: AOCDay {
final class Day08: AdventOfCodeDay {
let title = "Haunted Wasteland"
let path: String
private let nodes: [String: Node]

Expand Down
3 changes: 2 additions & 1 deletion Sources/Day09/Day09.swift → Sources/Day09.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import AoCTools

final class Day09: AOCDay {
final class Day09: AdventOfCodeDay {
let title = "Mirage Maintenance"
let sequences: [[Int]]

init(input: String) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Day10/Day10.swift → Sources/Day10.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ private enum Tile: Character {
case start = "S"
}

final class Day10: AOCDay {
final class Day10: AdventOfCodeDay {
let title = "Pipe Maze"
private let field: [[Tile]]

init(input: String) {
Expand Down
4 changes: 3 additions & 1 deletion Sources/Day11/Day11.swift → Sources/Day11.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import AoCTools

final class Day11: AOCDay {
final class Day11: AdventOfCodeDay {
let title = "Cosmic Expansion"

let galaxies: [Point]

init(input: String) {
Expand Down
4 changes: 3 additions & 1 deletion Sources/Day12/Day12.swift → Sources/Day12.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ private struct Row: Hashable {
}
}

final class Day12: AOCDay {
final class Day12: AdventOfCodeDay {
let title = "Hot Springs"

private let rows: [Row]

init(input: String) {
Expand Down
4 changes: 3 additions & 1 deletion Sources/Day13/Day13.swift → Sources/Day13.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ struct Pattern {
}
}

final class Day13: AOCDay {
final class Day13: AdventOfCodeDay {
let title = "Point of Incidence"

let patterns: [Pattern]

init(input: String) {
Expand Down
4 changes: 3 additions & 1 deletion Sources/Day14/Day14.swift → Sources/Day14.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import AoCTools

final class Day14: AOCDay {
final class Day14: AdventOfCodeDay {
let title = "Parabolic Reflector Dish"

private let platform: [Point: Character]
let maxX: Int
let maxY: Int
Expand Down
4 changes: 3 additions & 1 deletion Sources/Day15/Day15.swift → Sources/Day15.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ private class Box {
var lenses = [Lens]()
}

final class Day15: AOCDay {
final class Day15: AdventOfCodeDay {
let title = "Lens Library"

let tokens: [String]

init(input: String) {
Expand Down
4 changes: 3 additions & 1 deletion Sources/Day16/Day16.swift → Sources/Day16.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ private struct Beam: Hashable {
}
}

final class Day16: AOCDay {
final class Day16: AdventOfCodeDay {
let title = "The Floor Will Be Lava"

let grid: [[Character]]
let maxX: Int
let maxY: Int
Expand Down
4 changes: 3 additions & 1 deletion Sources/Day17/Day17.swift → Sources/Day17.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ private struct City: Pathfinding {
}
}

final class Day17: AOCDay {
final class Day17: AdventOfCodeDay {
let title = "Clumsy Crucible"

private let grid: [[Int]]
private var maxX: Int { grid[0].count }
private var maxY: Int { grid.count }
Expand Down
4 changes: 3 additions & 1 deletion Sources/Day18/Day18.swift → Sources/Day18.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ private struct Dig {
}
}

final class Day18: AOCDay {
final class Day18: AdventOfCodeDay {
let title = "Lavaduct Lagoon"

private let digs: [Dig]

init(input: String) {
Expand Down
4 changes: 3 additions & 1 deletion Sources/Day19/Day19.swift → Sources/Day19.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ private struct Range {
}
}

final class Day19: AOCDay {
final class Day19: AdventOfCodeDay {
let title = "Aplenty"

private let workflows: [String: Workflow]
private let parts: [Part]

Expand Down
4 changes: 3 additions & 1 deletion Sources/Day20/Day20.swift → Sources/Day20.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ private final class Output: CommunicationsModule {
// drop all input pulses
}

final class Day20: AOCDay {
final class Day20: AdventOfCodeDay {
let title = "Pulse Propagation"

private let modules: [String: CommunicationsModule]

init(input: String) {
Expand Down
4 changes: 3 additions & 1 deletion Sources/Day21/Day21.swift → Sources/Day21.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ private struct Grid {
}
}

final class Day21: AOCDay {
final class Day21: AdventOfCodeDay {
let title = "Step Counter"

private let grid: Grid
let maxSteps: Int

Expand Down
4 changes: 3 additions & 1 deletion Sources/Day22/Day22.swift → Sources/Day22.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ private struct Brick {
}
}

final class Day22: AOCDay {
final class Day22: AdventOfCodeDay {
let title = "Sand Slabs"

private let bricks: [Brick]

init(input: String) {
Expand Down
4 changes: 3 additions & 1 deletion Sources/Day23/Day23.swift → Sources/Day23.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ private enum Tile: Equatable {
}
}

final class Day23: AOCDay {
final class Day23: AdventOfCodeDay {
let title = "A Long Walk"

private let maze: [Point: Tile]
private let start: Point
private let end: Point
Expand Down
4 changes: 3 additions & 1 deletion Sources/Day24/Day24.swift → Sources/Day24.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ private struct Stone {
}
}

final class Day24: AOCDay {
final class Day24: AdventOfCodeDay {
let title = "Never Tell Me The Odds"

private let stones: [Stone]
private let range: ClosedRange<Double>

Expand Down
4 changes: 3 additions & 1 deletion Sources/Day25/Day25.swift → Sources/Day25.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import AoCTools

final class Day25: AOCDay {
final class Day25: AdventOfCodeDay {
let title = "Snowverload"

let connections: [String: Set<String>]

init(input: String) {
Expand Down
Empty file added Sources/Inputs/.gitkeep
Empty file.
1 change: 0 additions & 1 deletion Tests/Day01Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day01Tests: XCTestCase {
let testInput = """
1abc2
Expand Down
1 change: 0 additions & 1 deletion Tests/Day02Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day02Tests: XCTestCase {
let testInput = """
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Expand Down
1 change: 0 additions & 1 deletion Tests/Day03Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day03Tests: XCTestCase {
let testInput = """
467..114..
Expand Down
Loading

0 comments on commit d304d78

Please sign in to comment.