Reorganised packages
This commit is contained in:
parent
951cf5f12c
commit
96cf4aff3b
@ -6,6 +6,16 @@ import PackageDescription
|
|||||||
let package = Package(
|
let package = Package(
|
||||||
name: "aoc2021",
|
name: "aoc2021",
|
||||||
platforms: [.macOS(.v12)],
|
platforms: [.macOS(.v12)],
|
||||||
|
products: [
|
||||||
|
.library(
|
||||||
|
name: "Runner",
|
||||||
|
targets: ["Runner"]),
|
||||||
|
.executable(name: "01", targets: ["01"]),
|
||||||
|
.executable(name: "02", targets: ["02"]),
|
||||||
|
.executable(name: "03", targets: ["03"]),
|
||||||
|
.executable(name: "04", targets: ["04"]),
|
||||||
|
.executable(name: "05", targets: ["05"])
|
||||||
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
// Dependencies declare other packages that this package depends on.
|
// Dependencies declare other packages that this package depends on.
|
||||||
// .package(url: /* package url */, from: "1.0.0"),
|
// .package(url: /* package url */, from: "1.0.0"),
|
||||||
@ -17,17 +27,37 @@ let package = Package(
|
|||||||
targets: [
|
targets: [
|
||||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||||
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
||||||
|
.target(
|
||||||
|
name: "Runner",
|
||||||
|
path: "Sources/Runner",
|
||||||
|
resources: [.process("Resources")]
|
||||||
|
),
|
||||||
.executableTarget(
|
.executableTarget(
|
||||||
name: "aoc2021",
|
name: "01",
|
||||||
|
dependencies: [.targetItem(name: "Runner", condition: nil)]
|
||||||
|
),
|
||||||
|
.executableTarget(
|
||||||
|
name: "02",
|
||||||
|
dependencies: [.targetItem(name: "Runner", condition: nil)]
|
||||||
|
),
|
||||||
|
.executableTarget(
|
||||||
|
name: "03",
|
||||||
|
dependencies: [.targetItem(name: "Runner", condition: nil)]
|
||||||
|
),
|
||||||
|
.executableTarget(
|
||||||
|
name: "04",
|
||||||
|
dependencies: [
|
||||||
|
.targetItem(name: "Runner", condition: nil)
|
||||||
|
],
|
||||||
|
resources: []
|
||||||
|
),
|
||||||
|
.executableTarget(
|
||||||
|
name: "05",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
//.product(name: "Collections", package: "swift-collections")
|
//.product(name: "Collections", package: "swift-collections")
|
||||||
|
.targetItem(name: "Runner", condition: nil)
|
||||||
],
|
],
|
||||||
resources: [
|
resources: []
|
||||||
.process("Resources"),
|
)
|
||||||
]
|
|
||||||
),
|
|
||||||
.testTarget(
|
|
||||||
name: "aoc2021Tests",
|
|
||||||
dependencies: ["aoc2021"]),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -6,8 +6,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import Runner
|
||||||
|
|
||||||
struct Day01 {
|
struct Day01: Runnable {
|
||||||
let inputPath: String
|
let inputPath: String
|
||||||
|
|
||||||
|
|
11
Sources/01/main.swift
Normal file
11
Sources/01/main.swift
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//
|
||||||
|
// File.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Max Nuding on 05.12.21.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import Runner
|
||||||
|
|
||||||
|
Runner(target: Day01.self, day: "01").run()
|
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import Runnerer
|
||||||
|
|
||||||
enum Direction: String {
|
enum Direction: String {
|
||||||
case forward
|
case forward
|
||||||
@ -39,7 +40,7 @@ struct MoveCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Day02 {
|
struct Day02: Runnable {
|
||||||
let inputPath: String
|
let inputPath: String
|
||||||
|
|
||||||
|
|
11
Sources/02/main.swift
Normal file
11
Sources/02/main.swift
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//
|
||||||
|
// File.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Max Nuding on 05.12.21.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import Runner
|
||||||
|
|
||||||
|
Runner(target: Day02.self, day: "02").run()
|
@ -6,8 +6,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import Runner
|
||||||
|
|
||||||
struct Day03 {
|
struct Day03: Runnable {
|
||||||
let inputPath: String
|
let inputPath: String
|
||||||
|
|
||||||
func run() {
|
func run() {
|
11
Sources/03/main.swift
Normal file
11
Sources/03/main.swift
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//
|
||||||
|
// File.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Max Nuding on 05.12.21.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import Runner
|
||||||
|
|
||||||
|
Runner(target: Day03.self, day: "03").run()
|
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import Runner
|
||||||
|
|
||||||
struct Board {
|
struct Board {
|
||||||
var numbers: [[Int?]]
|
var numbers: [[Int?]]
|
||||||
@ -48,7 +49,7 @@ struct Board {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Day04 {
|
struct Day04: Runnable {
|
||||||
let inputPath: String
|
let inputPath: String
|
||||||
|
|
||||||
func run() {
|
func run() {
|
11
Sources/04/main.swift
Normal file
11
Sources/04/main.swift
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//
|
||||||
|
// File.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Max Nuding on 05.12.21.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import Runner
|
||||||
|
|
||||||
|
Runner(target: Day04.self, day: "04").run()
|
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import Runner
|
||||||
|
|
||||||
struct Line: CustomStringConvertible {
|
struct Line: CustomStringConvertible {
|
||||||
let from: Point
|
let from: Point
|
||||||
@ -79,7 +80,7 @@ struct Field: CustomStringConvertible {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Day05 {
|
struct Day05: Runnable {
|
||||||
let inputPath: String
|
let inputPath: String
|
||||||
|
|
||||||
func run() {
|
func run() {
|
11
Sources/05/main.swift
Normal file
11
Sources/05/main.swift
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//
|
||||||
|
// File.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Max Nuding on 05.12.21.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import Runner
|
||||||
|
|
||||||
|
Runner(target: Day05.self, day: "05").run()
|
38
Sources/Runner/Runner.swift
Normal file
38
Sources/Runner/Runner.swift
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
//
|
||||||
|
// File.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Max Nuding on 05.12.21.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
public protocol Runnable {
|
||||||
|
init(inputPath: String)
|
||||||
|
func run()
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct Runner {
|
||||||
|
let target: Runnable.Type
|
||||||
|
let inputPath: String
|
||||||
|
let day: String
|
||||||
|
|
||||||
|
public init(target: Runnable.Type, day: String, isTest: Bool = false) {
|
||||||
|
let inputPath = isTest ? "\(day)_test" : day
|
||||||
|
let input = Bundle.module.path(forResource: inputPath, ofType: ".txt")!
|
||||||
|
self.inputPath = input
|
||||||
|
self.target = target
|
||||||
|
self.day = day
|
||||||
|
}
|
||||||
|
|
||||||
|
public func run() {
|
||||||
|
print("Starting day \(day)")
|
||||||
|
let start = CFAbsoluteTimeGetCurrent()
|
||||||
|
let runnable = target.init(inputPath: inputPath)
|
||||||
|
runnable.run()
|
||||||
|
let end = CFAbsoluteTimeGetCurrent()
|
||||||
|
let execTimeMs = round((end - start) * 1000.0 * 100.0) / 100.0
|
||||||
|
print("Finished in \(execTimeMs)ms")
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,50 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
//import Collections
|
|
||||||
/*
|
|
||||||
print("Starting day 01")
|
|
||||||
let input01 = Bundle.module.path(forResource: "01", ofType: ".txt")!
|
|
||||||
let start = CFAbsoluteTimeGetCurrent()
|
|
||||||
Day01(inputPath: input01).run()
|
|
||||||
let end = CFAbsoluteTimeGetCurrent()
|
|
||||||
let execTimeMs = round((end - start) * 1000.0 * 100.0) / 100.0
|
|
||||||
print("Finished in \(execTimeMs)ms")
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
print("Starting day 02")
|
|
||||||
let input02 = Bundle.module.path(forResource: "02", ofType: ".txt")!
|
|
||||||
let start = CFAbsoluteTimeGetCurrent()
|
|
||||||
Day02(inputPath: input02).run()
|
|
||||||
let end = CFAbsoluteTimeGetCurrent()
|
|
||||||
let execTimeMs = round((end - start) * 1000.0 * 100.0) / 100.0
|
|
||||||
print("Finished in \(execTimeMs)ms")
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
print("Starting day 03")
|
|
||||||
let input03 = Bundle.module.path(forResource: "03", ofType: ".txt")!
|
|
||||||
let start = CFAbsoluteTimeGetCurrent()
|
|
||||||
Day03(inputPath: input03).run()
|
|
||||||
let end = CFAbsoluteTimeGetCurrent()
|
|
||||||
let execTimeMs = round((end - start) * 1000.0 * 100.0) / 100.0
|
|
||||||
print("Finished in \(execTimeMs)ms")
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
print("Starting day 04")
|
|
||||||
let input03 = Bundle.module.path(forResource: "04", ofType: ".txt")!
|
|
||||||
let start = CFAbsoluteTimeGetCurrent()
|
|
||||||
Day04(inputPath: input03).run()
|
|
||||||
let end = CFAbsoluteTimeGetCurrent()
|
|
||||||
let execTimeMs = round((end - start) * 1000.0 * 100.0) / 100.0
|
|
||||||
print("Finished in \(execTimeMs)ms")
|
|
||||||
*/
|
|
||||||
|
|
||||||
print("Starting day 05")
|
|
||||||
let input03 = Bundle.module.path(forResource: "05", ofType: ".txt")!
|
|
||||||
let start = CFAbsoluteTimeGetCurrent()
|
|
||||||
Day05(inputPath: input03).run()
|
|
||||||
let end = CFAbsoluteTimeGetCurrent()
|
|
||||||
let execTimeMs = round((end - start) * 1000.0 * 100.0) / 100.0
|
|
||||||
print("Finished in \(execTimeMs)ms")
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user