Answer:
non-Pangrams: 819,
Pangrams: 181, of which 49 are perfect Pangrams (and 132 non-perfect)
Swift Code:
import Foundation
func loadStringArray(from url: URL, decoder: JSONDecoder = JSONDecoder()) -> [String] {
do {
let data = try Data(contentsOf: url, options: [.mappedIfSafe])
return try decoder.decode([String].self, from: data)
}
catch {
print(error)
}
return []
}
if let fileName = Array(CommandLine.arguments.dropFirst()).first {
let allStrings = loadStringArray(from: URL(filePath: fileName))
let converted = allStrings.map { str in str.lowercased().filter { $0 >= "a" && $0 <= "z" } }.map {str in
var ret = Array<Int>(repeating: 0, count: 26)
str.forEach {
if let i = $0.asciiValue, i >= 97, i <= 122 { ret[Int(i-97)] += 1 }
}
return ret
}
let pangram = converted.filter { conv in conv.allSatisfy { $0 >= 1 }}
let perfectpangram = converted.filter { $0.allSatisfy { $0 == 1 }}
print("non-Pangrams: \(converted.count - pangram.count),\nPangrams: \(pangram.count), of which \(perfectpangram.count) are perfect Pangrams")
}