Files
aoc-2025/template/source/day.swift
Andrew Glaze bf5f9e386b add template
2025-12-13 12:03:38 -05:00

96 lines
2.2 KiB
Swift

#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