import Foundation typealias Color = Character func readInput(_ filePath: String) throws -> ([[Color]], [[Color]]) { let content = try String(contentsOfFile: filePath, encoding: .ascii) let lines = content.split(separator: "\n") let towels = lines[0].split(separator: ", ").map(Array.init) let patterns = lines[1.. Int { if pattern.count == 0 { return 1 } if let cached = cache[pattern] { return cached } let r = towels .filter { pattern.starts(with: $0) } .map { matches(Array(pattern[$0.count..