Reorganised packages

This commit is contained in:
2021-12-05 11:43:02 +01:00
parent 951cf5f12c
commit 96cf4aff3b
19 changed files with 142 additions and 64 deletions

View File

@ -6,8 +6,9 @@
//
import Foundation
import Runner
struct Day01 {
struct Day01: Runnable {
let inputPath: String

11
Sources/01/main.swift Normal file
View 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()

View File

@ -6,6 +6,7 @@
//
import Foundation
import Runnerer
enum Direction: String {
case forward
@ -39,7 +40,7 @@ struct MoveCommand {
}
}
struct Day02 {
struct Day02: Runnable {
let inputPath: String

11
Sources/02/main.swift Normal file
View 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()

View File

@ -6,8 +6,9 @@
//
import Foundation
import Runner
struct Day03 {
struct Day03: Runnable {
let inputPath: String
func run() {

11
Sources/03/main.swift Normal file
View 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()

View File

@ -6,6 +6,7 @@
//
import Foundation
import Runner
struct Board {
var numbers: [[Int?]]
@ -48,7 +49,7 @@ struct Board {
}
}
struct Day04 {
struct Day04: Runnable {
let inputPath: String
func run() {

11
Sources/04/main.swift Normal file
View 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()

View File

@ -1,11 +1,12 @@
//
// File.swift
//
//
//
// Created by Max Nuding on 05.12.21.
//
import Foundation
import Runner
struct Line: CustomStringConvertible {
let from: Point
@ -79,7 +80,7 @@ struct Field: CustomStringConvertible {
}
}
struct Day05 {
struct Day05: Runnable {
let inputPath: String
func run() {

11
Sources/05/main.swift Normal file
View 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()

View 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")
}
}

View File

@ -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")