day2: impl romfs
This commit is contained in:
@@ -38,7 +38,7 @@ DATA := data
|
||||
INCLUDES := include
|
||||
GRAPHICS := gfx
|
||||
GFXBUILD := $(BUILD)
|
||||
#ROMFS := romfs
|
||||
ROMFS := romfs
|
||||
#GFXBUILD := $(ROMFS)/gfx
|
||||
APP_TITLE := day02
|
||||
APP_DESCRIPTION := aoc 2025
|
||||
|
||||
1
day02/romfs/test.txt
Normal file
1
day02/romfs/test.txt
Normal file
@@ -0,0 +1 @@
|
||||
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124
|
||||
@@ -5,8 +5,12 @@ import Foundation
|
||||
@main
|
||||
struct Day02 {
|
||||
static func run() {
|
||||
guard let input = realInput else {
|
||||
print("input sttring nil")
|
||||
return
|
||||
}
|
||||
print("Parsing...")
|
||||
let parsed = parseInput(realInput)
|
||||
let parsed = parseInput(input)
|
||||
print("Running Part 1...")
|
||||
part1(parsed)
|
||||
print("Running Part 2...")
|
||||
@@ -78,6 +82,14 @@ struct Day02 {
|
||||
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() {
|
||||
@@ -94,18 +106,36 @@ struct Day02 {
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
let testInput = """
|
||||
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124
|
||||
"""
|
||||
var testInput: String? = nil
|
||||
|
||||
let realInput = """
|
||||
492410748-492568208,246-390,49-90,16-33,142410-276301,54304-107961,12792-24543,3434259704-3434457648,848156-886303,152-223,1303-1870,8400386-8519049,89742532-89811632,535853-567216,6608885-6724046,1985013826-1985207678,585591-731454,1-13,12067202-12233567,6533-10235,6259999-6321337,908315-972306,831-1296,406-824,769293-785465,3862-5652,26439-45395,95-136,747698990-747770821,984992-1022864,34-47,360832-469125,277865-333851,2281-3344,2841977-2953689,29330524-29523460
|
||||
"""
|
||||
var realInput: String? = nil
|
||||
|
||||
Reference in New Issue
Block a user