I'm solving a puzzle (Advent of code 2022 day 8) by allocating an object for each digit in the input file. Using the sample input (25 digits) it works fine but doesn't scale to the 99^2 digits in the full input file. Xcode stops responding after allocating the objects.
What is the limitation that I need to be aware of?
import Foundation
let sampleInput = """
30373
25512
65332
33549
35390
"""
let fileURL = Bundle.main.url(forResource: "input", withExtension: "txt")
let content = try String(contentsOf: fileURL!, encoding: String.Encoding.utf8)
//Using a class because classes are passed by reference,
//so I can create a transposed view the grid containing the same trees
class Tree {
var height: Int
var visibleFromLeft: Bool = false
var visibleFromRight: Bool = false
var visibleFromTop: Bool = false
var visibleFromBottom: Bool = false
var visible: Bool {
get {
return visibleFromLeft || visibleFromRight || visibleFromTop || visibleFromBottom
}
}
init(height: Int) {
self.height = height
}
}
let gridOfRows = content.split(separator: "\n").map({rowStr in
var row: [Tree] = []
for c in rowStr {
row.append(Tree(height: Int(String(c))!))
}
return row
})