Get string operations working on 3ds
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user