-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAOCDay.swift
42 lines (35 loc) · 966 Bytes
/
AOCDay.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// AOCDay.swift
//
// Advent of Code Tools
//
@MainActor
public protocol Runnable {
static var input: String { get }
init(input: String)
func run()
}
@available(*, deprecated, message: "Use AdventOfCodeDay instead")
public protocol AOCDay: Runnable {
var day: String { get }
var title: String { get }
associatedtype Solution1
func part1() -> Solution1
associatedtype Solution2
func part2() -> Solution2
}
extension AOCDay {
public static var input: String { "" }
public var day: String { "\(Int("\(Self.self)".suffix(2))!)" }
public var title: String { "Day \(day)" }
public func run() {
run(part: 1, part1)
run(part: 2, part2)
}
private func run<T>(part: Int, _ fun: () -> T) {
let timer = Timer(day, fun: "'\(title)' part \(part)")
let solution = fun()
timer.show()
print("Solution for day \(day) '\(title)' part \(part): \(solution)")
}
}