diff --git a/day01/source/day01.swift b/day01/source/day01.swift index 117170f..dc89548 100644 --- a/day01/source/day01.swift +++ b/day01/source/day01.swift @@ -73,6 +73,7 @@ struct Day01 { static func main() { gfxInitDefault() consoleInit(GFX_TOP, nil) + guard romfsInit() == 0 else { print("Couldn't init RomFS") return diff --git a/day02/Makefile b/day02/Makefile index 2c36b19..0be7b6e 100644 --- a/day02/Makefile +++ b/day02/Makefile @@ -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 diff --git a/day02/romfs/test.txt b/day02/romfs/test.txt new file mode 100644 index 0000000..a3f22ef --- /dev/null +++ b/day02/romfs/test.txt @@ -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 diff --git a/day02/source/day02.swift b/day02/source/day02.swift index 1a178b1..3aa5491 100644 --- a/day02/source/day02.swift +++ b/day02/source/day02.swift @@ -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