add template
This commit is contained in:
95
template/source/day.swift
Normal file
95
template/source/day.swift
Normal file
@@ -0,0 +1,95 @@
|
||||
#if !hasFeature(Embedded)
|
||||
import Foundation
|
||||
#endif
|
||||
|
||||
@main
|
||||
struct Day {
|
||||
static func run() {
|
||||
guard let input = testInput else {
|
||||
print("input sttring nil")
|
||||
return
|
||||
}
|
||||
print("Parsing...")
|
||||
let parsed = parseInput(input)
|
||||
print("Running Part 1...")
|
||||
part1(parsed)
|
||||
print("Running Part 2...")
|
||||
part2(parsed)
|
||||
print("Finished!")
|
||||
}
|
||||
|
||||
typealias ParsedInput = String
|
||||
|
||||
static func parseInput(_ input: String) -> ParsedInput {
|
||||
return input
|
||||
}
|
||||
|
||||
static func part1(_ input: ParsedInput) {
|
||||
}
|
||||
|
||||
static func part2(_ input: ParsedInput) {
|
||||
}
|
||||
|
||||
#if hasFeature(Embedded)
|
||||
static func main() {
|
||||
gfxInitDefault()
|
||||
consoleInit(GFX_TOP, nil)
|
||||
|
||||
guard romfsInit() == 0 else {
|
||||
print("Couldn't init RomFS")
|
||||
return
|
||||
}
|
||||
|
||||
testInput = stringFromFile("romfs:/test.txt")
|
||||
realInput = stringFromFile("romfs:/input.txt")
|
||||
|
||||
run()
|
||||
|
||||
while aptMainLoop() {
|
||||
hidScanInput()
|
||||
let kDown = hidKeysDown()
|
||||
if kDown & KEY_START != 0 {
|
||||
break
|
||||
}
|
||||
|
||||
gfxFlushBuffers()
|
||||
gfxSwapBuffers()
|
||||
}
|
||||
|
||||
romfsExit()
|
||||
gfxExit()
|
||||
}
|
||||
|
||||
static func stringFromFile(_ path: String) -> String? {
|
||||
let file = fopen(path, "r")
|
||||
var ret = ""
|
||||
var buf = [CChar](repeating: 0, count: 100)
|
||||
while fgets(&buf, 100, file) != nil {
|
||||
ret += String(cString: buf)
|
||||
}
|
||||
guard feof(file) != 0 else {
|
||||
print("Error reading file \(path)")
|
||||
return nil
|
||||
}
|
||||
while ret.first?.isNewline ?? false {
|
||||
ret.removeFirst()
|
||||
}
|
||||
while ret.last?.isNewline ?? false {
|
||||
ret.removeLast()
|
||||
}
|
||||
return ret
|
||||
}
|
||||
#else
|
||||
static func main() {
|
||||
testInput = try? String(contentsOfFile: "romfs/test.txt").trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
realInput = try? String(contentsOfFile: "romfs/input.txt").trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
run()
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
var testInput: String? = nil
|
||||
|
||||
var realInput: String? = nil
|
||||
Reference in New Issue
Block a user