Get string operations working on 3ds

This commit is contained in:
Andrew Glaze
2025-12-07 12:45:22 -05:00
parent d943c2d074
commit 0acb7c74db
21 changed files with 30432 additions and 23 deletions

View File

@@ -37,10 +37,10 @@ struct Day01 {
}
static func parseInput(_ input: String) -> [(Direction, Int)] {
input.utf8.split(separator: "\n".utf8.first!).map({ line in
input.split(separator: "\n").map({ line in
return (
Direction(line.first!),
atoi(line.dropFirst())
Int(line.dropFirst())!
)
})
}
@@ -87,20 +87,6 @@ struct Day01 {
}
print("Part 2: \(count)")
}
static func atoi(_ str: Substring.UTF8View) -> Int {
var result = 0
for char in str {
if char >= 0x30 && char <= 0x39 {
result = result * 10 + (Int(char) - 0x30)
} else {
break
}
}
return result
}
}
@@ -108,10 +94,10 @@ enum Direction {
case Left
case Right
init(_ char: UInt8) {
init(_ char: Character) {
self = switch char {
case "L".utf8.first: Direction.Left
case "R".utf8.first: Direction.Right
case "L": Direction.Left
case "R": Direction.Right
default: fatalError()
}
}

View File

@@ -1,18 +0,0 @@
#include <stdlib.h>
#include <malloc.h>
#include <errno.h>
int posix_memalign(void **res, size_t align, size_t len) {
if (align < sizeof(void *)) return 22;
void *mem = memalign(align, len);
if (!mem) return errno;
*res = mem;
return 0;
}
int getentropy(void *buffer, size_t length) {
for (int i = 0; i < length; i++) {
((int*)buffer)[i] = rand();
}
return 0;
}